cedric pushed a commit to branch master.

http://git.enlightenment.org/core/efl.git/commit/?id=826998c15e0e24882ed8bea09c6f3252bf782f07

commit 826998c15e0e24882ed8bea09c6f3252bf782f07
Author: Srivardhan Hebbar <sri.heb...@samsung.com>
Date:   Wed Sep 23 14:03:27 2015 -0700

    ecore_exe: fix memory leak on realloc.
    
    Summary: Signed-off-by: Srivardhan Hebbar <sri.heb...@samsung.com>
    
    Reviewers: cedric
    
    Subscribers: cedric
    
    Differential Revision: https://phab.enlightenment.org/D3091
    
    Signed-off-by: Cedric BAIL <ced...@osg.samsung.com>
---
 src/lib/ecore/ecore_exe_posix.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/src/lib/ecore/ecore_exe_posix.c b/src/lib/ecore/ecore_exe_posix.c
index 1fd1783..9e64cba 100644
--- a/src/lib/ecore/ecore_exe_posix.c
+++ b/src/lib/ecore/ecore_exe_posix.c
@@ -1095,7 +1095,7 @@ _ecore_exe_data_generic_handler(void             *data,
    if ((fd_handler)
        && (ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_READ)))
    {
-      unsigned char *inbuf;
+      unsigned char *inbuf, *temp;
       int inbuf_num;
 
       /* Get any left over data from last time. */
@@ -1135,9 +1135,15 @@ _ecore_exe_data_generic_handler(void             *data,
          }
          if (num > 0) /* data got read. */
          {
+            temp = inbuf;
             inbuf = realloc(inbuf, inbuf_num + num);
-            memcpy(inbuf + inbuf_num, buf, num);
-            inbuf_num += num;
+            if (inbuf)
+              {
+                 memcpy(inbuf + inbuf_num, buf, num);
+                 inbuf_num += num;
+              }
+            else // realloc fails and returns NULL.
+               inbuf = temp;
          }
          else
          { /* No more data to read. */

-- 


Reply via email to