From 0734686074700b40b6cff80d7279a5285d3c0c0f Mon Sep 17 00:00:00 2001 From: YoungJun Cho Date: Mon, 28 Nov 2016 18:04:58 +0900 Subject: [PATCH] tdm_helper: clean up _tdm_helper_dump_png() This patch cleans up _tdm_helper_dump_png() not to skip resources release. Change-Id: Ic2384c0e5cc1335428f455760efb5c691e3600f9 Signed-off-by: YoungJun Cho --- src/tdm_helper.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/tdm_helper.c b/src/tdm_helper.c index 51b5ddf..95dbe7f 100644 --- a/src/tdm_helper.c +++ b/src/tdm_helper.c @@ -128,6 +128,11 @@ _tdm_helper_dump_png(const char *file, const void *data, int width, const int pixel_size = 4; // RGBA png_bytep *row_pointers = png_malloc(pPngStruct, height * sizeof(png_byte *)); + if (!row_pointers) { + png_destroy_write_struct(&pPngStruct, &pPngInfo); + fclose(fp); + return; + } unsigned int *blocks = (unsigned int *)data; int y = 0; @@ -136,6 +141,15 @@ _tdm_helper_dump_png(const char *file, const void *data, int width, for (; y < height; ++y) { png_bytep row = png_malloc(pPngStruct, sizeof(png_byte) * width * pixel_size); + if (!row) { + for (x = 0; x < y; x++) + png_free(pPngStruct, row_pointers[x]); + png_free(pPngStruct, row_pointers); + png_destroy_write_struct(&pPngStruct, &pPngInfo); + fclose(fp); + return; + } + row_pointers[y] = (png_bytep)row; for (x = 0; x < width; ++x) { unsigned int curBlock = blocks[y * width + x]; -- 2.7.4