From 2f882b02d5ff65219b1702a4e880582afeb185c4 Mon Sep 17 00:00:00 2001 From: Cyril Hrubis Date: Sun, 27 May 2012 22:43:51 +0200 Subject: [PATCH] loaders: Add forgotten libpng cleanup for image loader. --- libs/loaders/GP_PNG.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/libs/loaders/GP_PNG.c b/libs/loaders/GP_PNG.c index 742cf469..51ea49cd 100644 --- a/libs/loaders/GP_PNG.c +++ b/libs/loaders/GP_PNG.c @@ -96,7 +96,7 @@ static const char *interlace_type_name(int interlace) GP_Context *GP_ReadPNG(FILE *f, GP_ProgressCallback *callback) { png_structp png; - png_infop png_info = NULL; + png_infop png_info = NULL; png_uint_32 w, h; int depth, color_type, interlace_type; GP_PixelType pixel_type = GP_PIXEL_UNKNOWN; @@ -211,21 +211,22 @@ GP_Context *GP_ReadPNG(FILE *f, GP_ProgressCallback *callback) if (GP_ProgressCallbackReport(callback, y, h, w)) { GP_DEBUG(1, "Operation aborted"); - err= ECANCELED; + err = ECANCELED; goto err3; } } + + png_destroy_read_struct(&png, &png_info, NULL); GP_ProgressCallbackDone(callback); - + return res; err3: GP_ContextFree(res); err2: png_destroy_read_struct(&png, png_info ? &png_info : NULL, NULL); err1: - fclose(f); errno = err; return NULL; } @@ -233,11 +234,16 @@ err1: GP_Context *GP_LoadPNG(const char *src_path, GP_ProgressCallback *callback) { FILE *f; + GP_Context *res; if (GP_OpenPNG(src_path, &f)) return NULL; - return GP_ReadPNG(f, callback); + res = GP_ReadPNG(f, callback); + + fclose(f); + + return res; } /* -- 2.11.4.GIT