tdm_helper: clean up _tdm_helper_dump_png() 97/100497/2
authorYoungJun Cho <yj44.cho@samsung.com>
Mon, 28 Nov 2016 09:04:58 +0000 (18:04 +0900)
committerSooChan Lim <sc1.lim@samsung.com>
Mon, 28 Nov 2016 09:54:09 +0000 (01:54 -0800)
This patch cleans up _tdm_helper_dump_png() not to skip resources release.

Change-Id: Ic2384c0e5cc1335428f455760efb5c691e3600f9
Signed-off-by: YoungJun Cho <yj44.cho@samsung.com>
src/tdm_helper.c

index 51b5ddf..95dbe7f 100644 (file)
@@ -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];