e/core: Fix minor mem leak when reading module paths
authorStafford Horne <shorne@gmail.com>
Fri, 20 Nov 2015 01:44:45 +0000 (20:44 -0500)
committerMike Blumenkrantz <zmike@osg.samsung.com>
Fri, 20 Nov 2015 01:44:45 +0000 (20:44 -0500)
Summary:
Found this with a quick valgrind session.  For paths that are not directories, if we fail the `ecore_file_is_dir` condition memory will not be freed.

The change is to use the default e_path freeing function.

Test Plan:
Run enlightenment in valgrind.  It should no longer show a mem leak like below.

```
==6912== 8 bytes in 1 blocks are definitely lost in loss record 186 of 5,940
==6912==    at 0x4C28C50: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==6912==    by 0x4D8574: e_path_dir_list_get (e_path.c:326)
==6912==    by 0x4D1BA4: e_module_init.part.0 (e_module.c:183)
==6912==    by 0x4D1DA8: e_module_init (e_module.c:153)
==6912==    by 0x4371ED: main (e_main.c:868)
```

Reviewers: zmike

Subscribers: cedric, seoz

Differential Revision: https://phab.enlightenment.org/D3356

src/bin/e_module.c

index 2e1648f46b1a4fd848a29637682273cc8ebb04e9..ffae12ff404874a3dacc1c0437677035c0e30f00 100644 (file)
@@ -152,6 +152,7 @@ EINTERN int
 e_module_init(void)
 {
    Eina_List *module_paths;
+   Eina_List *next_path;
    E_Path_Dir *epd;
    Eio_Monitor *mon;
    Eio_File *ls;
@@ -181,7 +182,7 @@ e_module_init(void)
           }
      }
    module_paths = e_path_dir_list_get(path_modules);
-   EINA_LIST_FREE(module_paths, epd)
+   EINA_LIST_FOREACH(module_paths, next_path, epd)
      {
         if (ecore_file_is_dir(epd->dir))
           {
@@ -192,10 +193,9 @@ e_module_init(void)
              ls = eio_file_direct_ls(epd->dir, _module_filter_cb, _module_main_cb, _module_done_cb, _module_error_cb, data);
              _e_module_path_monitors = eina_list_append(_e_module_path_monitors, mon);
              _e_module_path_lists = eina_list_append(_e_module_path_lists, ls);
-             eina_stringshare_del(epd->dir);
-             free(epd);
           }
      }
+   e_path_dir_list_free(module_paths);
 
    return 1;
 }