Elm: module unloading
authorBruno Dilly <bdilly@profusion.mobi>
Tue, 19 Jun 2012 18:24:17 +0000 (18:24 +0000)
committerBruno Dilly <bdilly@profusion.mobi>
Tue, 19 Jun 2012 18:24:17 +0000 (18:24 +0000)
Implements the module unloading to all modules on elm_module_shutdown.
This change also fixes a memory leak within elm_module picked by valgrind.

Here follows the valgrind log:

96 bytes in 1 blocks are definitely lost in loss record 105 of 168
    at 0x4C29DB4: calloc (
            in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
            by 0x52065B6: _elm_module_add (elm_module.c:223)
            by 0x520669E: _elm_module_parse (elm_module.c:77)
            by 0x51F1249: elm_quicklaunch_sub_init (elm_main.c:437)
            by 0x51F12BE: elm_init (elm_main.c:180)

Patch by Leandro Dorileo <dorileo@profusion.mobi>

SVN revision: 72499

src/lib/elm_module.c

index 396e9de..8357cad 100644 (file)
@@ -42,9 +42,21 @@ _elm_module_init(void)
 void
 _elm_module_shutdown(void)
 {
-   // FIXME: unload all modules
-   if (modules) eina_hash_free(modules);
-   modules = NULL;
+   Eina_Iterator *it;
+   Elm_Module *m;
+
+   if (modules)
+     {
+        it = eina_hash_iterator_data_new(modules);
+
+        EINA_ITERATOR_FOREACH(it, m)
+           _elm_module_del(m);
+
+        eina_iterator_free(it);
+        eina_hash_free(modules);
+        modules = NULL;
+     }
+
    if (modules_as) eina_hash_free(modules_as);
    modules_as = NULL;
 }