emile: fix memory leak.
authorCedric BAIL <cedric@osg.samsung.com>
Sat, 25 Apr 2015 17:27:20 +0000 (19:27 +0200)
committerCedric BAIL <cedric@osg.samsung.com>
Sat, 25 Apr 2015 17:27:20 +0000 (19:27 +0200)
CID 1288924 & 1288923

src/lib/emile/emile_image.c

index c5eb1f3..06a5da4 100644 (file)
@@ -1599,6 +1599,9 @@ _emile_jpeg_data(Emile_Image *image,
    volatile int degree = 0;
    volatile Eina_Bool change_wh = EINA_FALSE;
    Eina_Bool line_done = EINA_FALSE;
+   Eina_Bool ptrg_free = EINA_FALSE;
+   Eina_Bool ptrag_free = EINA_FALSE;
+   Eina_Bool r = EINA_FALSE;
    unsigned int length;
 
    if (sizeof(Emile_Image_Property) != property_size)
@@ -1781,11 +1784,13 @@ _emile_jpeg_data(Emile_Image *image,
           {
              ptrg = malloc(w * h * sizeof(uint8_t));
              ptrg_rotate = ptrg;
+             ptrg_free = EINA_TRUE;
           }
         else if (prop->cspace == EMILE_COLORSPACE_AGRY88)
           {
              ptrag = malloc(w * h * sizeof(uint16_t));
              ptrag_rotate = ptrag;
+             ptrag_free = EINA_TRUE;
           }
         else
           {
@@ -2216,15 +2221,17 @@ done:
      }
    /* end data decoding */
    jpeg_finish_decompress(&cinfo);
-   jpeg_destroy_decompress(&cinfo);
-   _emile_jpeg_membuf_src_term(&cinfo);
    *error = EMILE_IMAGE_LOAD_ERROR_NONE;
-   return EINA_TRUE;
+   r = EINA_TRUE;
+
+ on_error:
+   if (ptrg_free) free(ptrg);
+   if (ptrag_free) free(ptrag);
 
-on_error:
    jpeg_destroy_decompress(&cinfo);
    _emile_jpeg_membuf_src_term(&cinfo);
-   return EINA_FALSE;
+   return r;
+
 }
 
 static void