raster pushed a commit to branch master.

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

commit fef4c2c29249f13bab8f2470160cbc0a874999a6
Author: Carsten Haitzler (Rasterman) <ras...@rasterman.com>
Date:   Thu Jul 13 18:48:00 2017 +0900

    efreet cache create binary - check realloc results and handle failure
    
    @fix
---
 src/bin/efreet/efreet_desktop_cache_create.c | 40 +++++++++++++++-------------
 1 file changed, 21 insertions(+), 19 deletions(-)

diff --git a/src/bin/efreet/efreet_desktop_cache_create.c 
b/src/bin/efreet/efreet_desktop_cache_create.c
index 3751f64b73..c749ffe4ee 100644
--- a/src/bin/efreet/efreet_desktop_cache_create.c
+++ b/src/bin/efreet/efreet_desktop_cache_create.c
@@ -96,27 +96,29 @@ cache_add(Eet_File *ef, const char *path, const char 
*file_id, int priority EINA
         char *data;
         Efreet_Cache_Array_String *array;
 
+#define ADD(hash) \
+   do { \
+      array = eina_hash_find((hash), data); \
+      if (!array) array = NEW(Efreet_Cache_Array_String, 1); \
+      void *p = realloc(array->array, \
+                        sizeof(char *) * (array->array_count + 1)); \
+      if (!p) { \
+         ERR("Out of memory"); \
+         exit(1); \
+      } \
+      array->array = p; \
+      array->array[array->array_count++] = desk->orig_path; \
+      eina_hash_set((hash), data, array); \
+   } while (0)
 #define ADD_LIST(list, hash) \
-        EINA_LIST_FOREACH((list), l, data) \
-        { \
-            array = eina_hash_find((hash), data); \
-            if (!array) \
-                array = NEW(Efreet_Cache_Array_String, 1); \
-            array->array = realloc(array->array, sizeof (char *) * 
(array->array_count + 1)); \
-            array->array[array->array_count++] = desk->orig_path; \
-            eina_hash_set((hash), data, array); \
-        }
+   EINA_LIST_FOREACH((list), l, data) { \
+      ADD(hash); \
+   }
 #define ADD_ELEM(elem, hash) \
-        if ((elem)) \
-        { \
-            data = (elem); \
-            array = eina_hash_find((hash), data); \
-            if (!array) \
-                array = NEW(Efreet_Cache_Array_String, 1); \
-            array->array = realloc(array->array, sizeof (char *) * 
(array->array_count + 1)); \
-            array->array[array->array_count++] = desk->orig_path; \
-            eina_hash_set((hash), data, array); \
-        }
+   if ((elem)) { \
+      data = (elem); \
+      ADD(hash); \
+   }
         /* Desktop Spec 1.0 */
         ADD_LIST(desk->mime_types, mime_types);
         ADD_LIST(desk->categories, categories);

-- 


Reply via email to