From b411be4be3abe2c5eecef59d36ce64f0efb89b00 Mon Sep 17 00:00:00 2001 From: Srivardhan Hebbar Date: Thu, 25 Dec 2014 21:34:45 +0100 Subject: [PATCH] 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 Reviewers: devilhorns Subscribers: cedric Differential Revision: https://phab.enlightenment.org/D1807 Signed-off-by: Cedric BAIL --- 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 a9a2615d81..9916a0deee 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 d146fbdaf9..ff0480d041 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