diff --git a/libretro-common/formats/png/rpng_decode_common.h b/libretro-common/formats/png/rpng_decode_common.h index a3ac0bfbac..ec367957f9 100644 --- a/libretro-common/formats/png/rpng_decode_common.h +++ b/libretro-common/formats/png/rpng_decode_common.h @@ -124,7 +124,6 @@ static bool png_reverse_filter(uint32_t *data, const struct png_ihdr *ihdr, struct rpng_process_t *pngp) { unsigned i; - bool ret = true; for (; pngp->h < ihdr->height; pngp->h++, pngp->inflate_buf += pngp->pitch, data += ihdr->width) @@ -173,7 +172,7 @@ static bool png_reverse_filter(uint32_t *data, const struct png_ihdr *ihdr, break; default: - GOTO_END_ERROR(); + return false; } if (ihdr->color_type == 0) @@ -192,9 +191,7 @@ static bool png_reverse_filter(uint32_t *data, const struct png_ihdr *ihdr, memcpy(pngp->prev_scanline, pngp->decoded_scanline, pngp->pitch); } -end: - png_reverse_filter_deinit(pngp); - return ret; + return true; } static bool png_reverse_filter_adam7(uint32_t *data, @@ -213,6 +210,7 @@ static bool png_reverse_filter_adam7(uint32_t *data, for (; pngp->pass < ARRAY_SIZE(passes); pngp->pass++) { + bool ret = true; unsigned pass_width, pass_height; struct png_ihdr tmp_ihdr; uint32_t *tmp_data = NULL; @@ -245,8 +243,12 @@ static bool png_reverse_filter_adam7(uint32_t *data, return false; } - if (!png_reverse_filter(tmp_data, - &tmp_ihdr, pngp)) + ret = png_reverse_filter(tmp_data, + &tmp_ihdr, pngp); + + png_reverse_filter_deinit(pngp); + + if (ret) { free(tmp_data); return false; diff --git a/libretro-common/formats/png/rpng_decode_fbio.c b/libretro-common/formats/png/rpng_decode_fbio.c index 27758fa646..fc25a9c174 100644 --- a/libretro-common/formats/png/rpng_decode_fbio.c +++ b/libretro-common/formats/png/rpng_decode_fbio.c @@ -353,8 +353,13 @@ bool rpng_load_image_argb(const char *path, uint32_t **data, &rpng.ihdr, &pngp)) GOTO_END_ERROR(); } - else if (!png_reverse_filter(*data, - &rpng.ihdr, &pngp)) + else + ret = png_reverse_filter(*data, + &rpng.ihdr, &pngp); + + png_reverse_filter_deinit(&pngp); + + if (!ret) GOTO_END_ERROR(); end: diff --git a/libretro-common/formats/png/rpng_decode_fnbio.c b/libretro-common/formats/png/rpng_decode_fnbio.c index 11aa26ac76..2148d4a282 100644 --- a/libretro-common/formats/png/rpng_decode_fnbio.c +++ b/libretro-common/formats/png/rpng_decode_fnbio.c @@ -257,6 +257,7 @@ bool rpng_nbio_load_image_argb_iterate(uint8_t *buf, struct rpng_t *rpng) bool rpng_nbio_load_image_argb_process(struct rpng_t *rpng, uint32_t **data, unsigned *width, unsigned *height) { + bool ret = true; struct rpng_process_t pngp = {0}; z_stream stream = {0}; @@ -313,11 +314,13 @@ bool rpng_nbio_load_image_argb_process(struct rpng_t *rpng, return false; } else - { - if (!png_reverse_filter(*data, - &rpng->ihdr, &pngp)) - return false; - } + ret = png_reverse_filter(*data, + &rpng->ihdr, &pngp); + + png_reverse_filter_deinit(&pngp); + + if (!ret) + return false; return true; }