emile: handling memory leak on realloc.
authorSrivardhan Hebbar <sri.hebbar@samsung.com>
Thu, 22 Oct 2015 19:19:01 +0000 (12:19 -0700)
committerCedric BAIL <cedric@osg.samsung.com>
Thu, 22 Oct 2015 19:20:55 +0000 (12:20 -0700)
Summary: Signed-off-by: Srivardhan Hebbar <sri.hebbar@samsung.com>

Reviewers: cedric

Differential Revision: https://phab.enlightenment.org/D3210

Signed-off-by: Cedric BAIL <cedric@osg.samsung.com>
src/lib/emile/emile_compress.c

index f45546d..e2d23d4 100644 (file)
@@ -38,7 +38,7 @@ emile_compress(const Eina_Binbuf *data,
                Emile_Compressor_Type t,
                Emile_Compressor_Level l)
 {
-   void *compact;
+   void *compact, *temp;
    int length;
    int level = l;
    Eina_Bool ok = EINA_FALSE;
@@ -55,19 +55,23 @@ emile_compress(const Eina_Binbuf *data,
         length = LZ4_compress((const char *)eina_binbuf_string_get(data),
                               compact,
                               eina_binbuf_length_get(data));
+        /* It is going to be smaller and should never fail, if it does you are in deep poo. */
+        temp = realloc(compact, length);
+        if (temp) temp = compact;
+
         if (length > 0)
           ok = EINA_TRUE;
-        /* It is going to be smaller and should never fail, if it does you are in deep poo. */
-        compact = realloc(compact, length);
         break;
 
       case EMILE_LZ4HC:
         length = LZ4_compressHC((const char *)eina_binbuf_string_get(data),
                                 compact,
                                 eina_binbuf_length_get(data));
+        temp = realloc(compact, length);
+        if (temp) compact = temp;
+
         if (length > 0)
           ok = EINA_TRUE;
-        compact = realloc(compact, length);
         break;
 
       case EMILE_ZLIB: