efreetd cache create - fix reallocs to bail on out of memory cleanly
authorCarsten Haitzler (Rasterman) <raster@rasterman.com>
Mon, 24 Jul 2017 04:37:57 +0000 (13:37 +0900)
committerCarsten Haitzler (Rasterman) <raster@rasterman.com>
Mon, 24 Jul 2017 04:37:57 +0000 (13:37 +0900)
src/bin/efreet/efreet_icon_cache_create.c

index 9cefc82..6fc709f 100644 (file)
@@ -237,6 +237,7 @@ cache_scan_path_dir(Efreet_Icon_Theme *theme,
         Efreet_Cache_Icon *icon;
         char *name;
         char *ext;
+        const char **tmp;
         unsigned int i;
 
         if (entry->type == EINA_FILE_DIR)
@@ -309,8 +310,16 @@ cache_scan_path_dir(Efreet_Icon_Theme *theme,
          */
         else if (!strcmp(icon->theme, theme->name.internal))
         {
-            icon->icons = realloc(icon->icons,
-                                  sizeof (Efreet_Cache_Icon_Element*) * (++icon->icons_count));
+            Efreet_Cache_Icon_Element **tmp2;
+
+            tmp2 = realloc(icon->icons,
+                          sizeof(Efreet_Cache_Icon_Element *) * (++icon->icons_count));
+            if (!tmp2)
+            {
+               ERR("Out of memory");
+               exit(1);
+            }
+            icon->icons = tmp2;
             icon->icons[i] = NEW(Efreet_Cache_Icon_Element, 1);
             icon->icons[i]->type = dir->type;
             icon->icons[i]->normal = dir->size.normal;
@@ -325,8 +334,14 @@ cache_scan_path_dir(Efreet_Icon_Theme *theme,
         }
 
         /* and finally store the path */
-        icon->icons[i]->paths = realloc(icon->icons[i]->paths,
-                                        sizeof (char*) * (icon->icons[i]->paths_count + 1));
+        tmp = realloc(icon->icons[i]->paths,
+                      sizeof(char *) * (icon->icons[i]->paths_count + 1));
+        if (!tmp)
+        {
+           ERR("Out of memory");
+           exit(1);
+        }
+        icon->icons[i]->paths = tmp;
         icon->icons[i]->paths[icon->icons[i]->paths_count] = eina_stringshare_add(entry->path);
         eina_array_push(strs, icon->icons[i]->paths[icon->icons[i]->paths_count++]);
     }