cedric pushed a commit to branch master.

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

commit b411be4be3abe2c5eecef59d36ce64f0efb89b00
Author: Srivardhan Hebbar <[email protected]>
Date:   Thu Dec 25 21:34:45 2014 +0100

    ecore: fix memory leak issues.
    
    Summary:
    eina_inarray_new returns NULL if malloc fails. This check was not 
performed. So have added the check for the error case and returning NULL if any 
of it fails.
    
    @fix
    
    Signed-off-by: Srivardhan Hebbar <[email protected]>
    
    Reviewers: devilhorns
    
    Subscribers: cedric
    
    Differential Revision: https://phab.enlightenment.org/D1807
    
    Signed-off-by: Cedric BAIL <[email protected]>
---
 src/lib/ecore_x/xcb/ecore_xcb_selection.c | 21 +++++++++++++++++----
 src/lib/ecore_x/xlib/ecore_x_selection.c  | 22 ++++++++++++++++++----
 2 files changed, 35 insertions(+), 8 deletions(-)

diff --git a/src/lib/ecore_x/xcb/ecore_xcb_selection.c 
b/src/lib/ecore_x/xcb/ecore_xcb_selection.c
index a9a2615..9916a0d 100644
--- a/src/lib/ecore_x/xcb/ecore_xcb_selection.c
+++ b/src/lib/ecore_x/xcb/ecore_xcb_selection.c
@@ -810,12 +810,15 @@ _ecore_xcb_selection_parser_xmozurl(const char *target 
EINA_UNUSED,
    if (!buf) return NULL;
    sel = calloc(1, sizeof(Ecore_X_Selection_Data_X_Moz_Url));
    if (!sel)
-     {
-        free(buf);
-        return NULL;
-     }
+     goto error_sel;
+
    sel->links = eina_inarray_new(sizeof(char*), 0);
+   if (!sel->links)
+     goto error_links;
+
    sel->link_names = eina_inarray_new(sizeof(char*), 0);
+   if (!sel->link_names)
+     goto error_link_names;
    prev = buf;
    for (n = memchr(buf, '\n', sz); n; n = memchr(prev, '\n', sz - (prev - 
buf)))
      {
@@ -834,6 +837,16 @@ _ecore_xcb_selection_parser_xmozurl(const char *target 
EINA_UNUSED,
    ECORE_XCB_SELECTION_DATA(sel)->data = (void*)data;
    ECORE_XCB_SELECTION_DATA(sel)->free = 
_ecore_xcb_selection_data_xmozurl_free;
    return sel;
+
+error_link_names:
+   eina_inarray_free(sel->links);
+
+error_links:
+   free(sel);
+
+error_sel:
+   free(buf);
+   return NULL;
 }
 
 static void *
diff --git a/src/lib/ecore_x/xlib/ecore_x_selection.c 
b/src/lib/ecore_x/xlib/ecore_x_selection.c
index d146fbd..ff0480d 100644
--- a/src/lib/ecore_x/xlib/ecore_x_selection.c
+++ b/src/lib/ecore_x/xlib/ecore_x_selection.c
@@ -924,13 +924,17 @@ _ecore_x_selection_parser_xmozurl(const char *target 
EINA_UNUSED,
    if (!buf) return NULL;
    sel = calloc(1, sizeof(Ecore_X_Selection_Data_X_Moz_Url));
    if (!sel)
-     {
-        free(buf);
-        return NULL;
-     }
+      goto error_sel;
+
    sz = strlen(buf);
    sel->links = eina_inarray_new(sizeof(char*), 0);
+   if (!sel->links)
+      goto error_links;
+
    sel->link_names = eina_inarray_new(sizeof(char*), 0);
+   if (!sel->link_names)
+      goto error_link_names;
+
    prev = buf;
    for (n = memchr(buf, '\n', sz); n; n = memchr(prev, '\n', sz - (prev - 
buf)))
      {
@@ -949,6 +953,16 @@ _ecore_x_selection_parser_xmozurl(const char *target 
EINA_UNUSED,
    ECORE_X_SELECTION_DATA(sel)->data = (void*)data;
    ECORE_X_SELECTION_DATA(sel)->free = _ecore_x_selection_data_xmozurl_free;
    return sel;
+
+error_link_names:
+   eina_inarray_free(sel->links);
+
+error_links:
+   free(sel);
+
+error_sel:
+   free(buf);
+   return NULL;
 }
 
 static int

-- 


Reply via email to