diff --git a/libretro-common/formats/png/rpng_decode_common.h b/libretro-common/formats/png/rpng_decode_common.h index fd0e116711..a3ac0bfbac 100644 --- a/libretro-common/formats/png/rpng_decode_common.h +++ b/libretro-common/formats/png/rpng_decode_common.h @@ -89,6 +89,14 @@ static void deinterlace_pass(uint32_t *data, const struct png_ihdr *ihdr, } } +static void png_reverse_filter_deinit(struct rpng_process_t *pngp) +{ + if (pngp->decoded_scanline) + free(pngp->decoded_scanline); + if (pngp->prev_scanline) + free(pngp->prev_scanline); +} + static bool png_reverse_filter_init(uint32_t *data, const struct png_ihdr *ihdr, struct rpng_process_t *pngp) { @@ -105,8 +113,7 @@ static bool png_reverse_filter_init(uint32_t *data, const struct png_ihdr *ihdr, if (!pngp->prev_scanline || !pngp->decoded_scanline) { - free(pngp->decoded_scanline); - free(pngp->prev_scanline); + png_reverse_filter_deinit(pngp); return false; } @@ -186,10 +193,7 @@ static bool png_reverse_filter(uint32_t *data, const struct png_ihdr *ihdr, } end: - if (pngp->decoded_scanline) - free(pngp->decoded_scanline); - if (pngp->prev_scanline) - free(pngp->prev_scanline); + png_reverse_filter_deinit(pngp); return ret; }