From a8ba4c28fbfe51a84bc856b6729e4ec3a1610c80 Mon Sep 17 00:00:00 2001 From: Chris Michael Date: Mon, 26 Sep 2016 14:01:15 -0400 Subject: [PATCH] elementary: Fix potential resource leak If we fail to allocate memory for savedtypes.types here, then the "known" array would end up leaking. Defer creation of 'known' array until after savedtypes.types is allocated, this way we don't leak. Fixes CID1363216 Signed-off-by: Chris Michael --- src/lib/elementary/elm_cnp.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/lib/elementary/elm_cnp.c b/src/lib/elementary/elm_cnp.c index fa379decca..dfe3ae7a4a 100644 --- a/src/lib/elementary/elm_cnp.c +++ b/src/lib/elementary/elm_cnp.c @@ -3477,7 +3477,6 @@ _wl_dnd_enter(void *data EINA_UNUSED, int type EINA_UNUSED, void *event) ev = event; - known = eina_array_new(5); available = ecore_wl2_offer_mimes_get(ev->offer); free(savedtypes.types); @@ -3486,9 +3485,12 @@ _wl_dnd_enter(void *data EINA_UNUSED, int type EINA_UNUSED, void *event) savedtypes.types = malloc(sizeof(char *) * savedtypes.ntypes); if (!savedtypes.types) return EINA_FALSE; + known = eina_array_new(5); + for (i = 0; i < eina_array_count(available); i++) { - savedtypes.types[i] = eina_stringshare_add(eina_array_data_get(available, i)); + savedtypes.types[i] = + eina_stringshare_add(eina_array_data_get(available, i)); if (savedtypes.types[i] == text_uri) { savedtypes.textreq = 1;