aboutsummaryrefslogtreecommitdiffstats
path: root/src/bin/efreet
diff options
context:
space:
mode:
authorCarsten Haitzler (Rasterman) <raster@rasterman.com>2017-07-13 18:48:00 +0900
committerCarsten Haitzler (Rasterman) <raster@rasterman.com>2017-07-16 15:56:02 +0900
commitfef4c2c29249f13bab8f2470160cbc0a874999a6 (patch)
treed48091300e0033c36cf0688c0a559295e269ed89 /src/bin/efreet
parenteo lexer - handle malloc failure with longjmp (diff)
downloadefl-fef4c2c29249f13bab8f2470160cbc0a874999a6.tar.gz
efreet cache create binary - check realloc results and handle failure
@fix
Diffstat (limited to 'src/bin/efreet')
-rw-r--r--src/bin/efreet/efreet_desktop_cache_create.c40
1 files 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);