summaryrefslogtreecommitdiff
path: root/src/lib/evas/file
diff options
context:
space:
mode:
authorJean-Philippe Andre <jp.andre@samsung.com>2017-02-21 14:46:02 +0900
committerJean-Philippe Andre <jp.andre@samsung.com>2017-02-21 15:15:51 +0900
commit3cb6d55ef0b1526062b1a444b260104b4fce069d (patch)
treebe47d1fab2a562ef4bebe7fecf64a03c58a2f235 /src/lib/evas/file
parentdb71d94173c61feb9cb91636d6244721190c19b4 (diff)
evas: Fix module memleak during evas_shutdown
This fixes a minor memory leak during shutdown. Note: This does NOT perform the dlclose (and still leaks the Eina_Module descriptor). Calling dlclose leads to a whole lot of other issues, so we avoid it.
Diffstat (limited to 'src/lib/evas/file')
-rw-r--r--src/lib/evas/file/evas_module.c52
1 files changed, 22 insertions, 30 deletions
diff --git a/src/lib/evas/file/evas_module.c b/src/lib/evas/file/evas_module.c
index f05870ad2b..31bceec120 100644
--- a/src/lib/evas/file/evas_module.c
+++ b/src/lib/evas/file/evas_module.c
@@ -347,6 +347,8 @@ static const struct {
347 { NULL, NULL } 347 { NULL, NULL }
348}; 348};
349 349
350static void _evas_module_hash_free_cb(void *data);
351
350/* this will alloc an Evas_Module struct for each module 352/* this will alloc an Evas_Module struct for each module
351 * it finds on the paths */ 353 * it finds on the paths */
352void 354void
@@ -356,12 +358,12 @@ evas_module_init(void)
356 358
357 evas_module_paths_init(); 359 evas_module_paths_init();
358 360
359 evas_modules[EVAS_MODULE_TYPE_ENGINE] = eina_hash_string_small_new(/* FIXME: Add a function to cleanup stuff. */ NULL); 361 evas_modules[EVAS_MODULE_TYPE_ENGINE] = eina_hash_string_small_new(_evas_module_hash_free_cb);
360 evas_modules[EVAS_MODULE_TYPE_IMAGE_LOADER] = eina_hash_string_small_new(/* FIXME: Add a function to cleanup stuff. */ NULL); 362 evas_modules[EVAS_MODULE_TYPE_IMAGE_LOADER] = eina_hash_string_small_new(_evas_module_hash_free_cb);
361 evas_modules[EVAS_MODULE_TYPE_IMAGE_SAVER] = eina_hash_string_small_new(/* FIXME: Add a function to cleanup stuff. */ NULL); 363 evas_modules[EVAS_MODULE_TYPE_IMAGE_SAVER] = eina_hash_string_small_new(_evas_module_hash_free_cb);
362 evas_modules[EVAS_MODULE_TYPE_OBJECT] = eina_hash_string_small_new(/* FIXME: Add a function to cleanup stuff. */ NULL); 364 evas_modules[EVAS_MODULE_TYPE_OBJECT] = eina_hash_string_small_new(_evas_module_hash_free_cb);
363 evas_modules[EVAS_MODULE_TYPE_VG_LOADER] = eina_hash_string_small_new(/* FIXME: Add a function to cleanup stuff. */ NULL); 365 evas_modules[EVAS_MODULE_TYPE_VG_LOADER] = eina_hash_string_small_new(_evas_module_hash_free_cb);
364 evas_modules[EVAS_MODULE_TYPE_VG_SAVER] = eina_hash_string_small_new(/* FIXME: Add a function to cleanup stuff. */ NULL); 366 evas_modules[EVAS_MODULE_TYPE_VG_SAVER] = eina_hash_string_small_new(_evas_module_hash_free_cb);
365 367
366 evas_engines = eina_array_new(4); 368 evas_engines = eina_array_new(4);
367 369
@@ -488,11 +490,22 @@ evas_module_unregister(const Evas_Module_Api *module, Evas_Module_Type type)
488 em = eina_hash_find(evas_modules[type], module->name); 490 em = eina_hash_find(evas_modules[type], module->name);
489 if (!em || em->definition != module) return EINA_FALSE; 491 if (!em || em->definition != module) return EINA_FALSE;
490 492
491 if (type == EVAS_MODULE_TYPE_ENGINE)
492 eina_array_data_set(evas_engines, em->id_engine - 1, NULL);
493
494 eina_hash_del(evas_modules[type], module->name, em); 493 eina_hash_del(evas_modules[type], module->name, em);
495 494
495 return EINA_TRUE;
496}
497
498static void
499_evas_module_hash_free_cb(void *data)
500{
501 Evas_Module *em = data;
502
503 // Note: This free callback leaks the Eina_Module, and does not call
504 // dlclose(). This is by choice as dlclose() leads to other issues.
505
506 if (!em) return;
507 if (em->id_engine > 0)
508 eina_array_data_set(evas_engines, em->id_engine - 1, NULL);
496 if (em->loaded) 509 if (em->loaded)
497 { 510 {
498 em->definition->func.close(em); 511 em->definition->func.close(em);
@@ -501,8 +514,6 @@ evas_module_unregister(const Evas_Module_Api *module, Evas_Module_Type type)
501 514
502 LKD(em->lock); 515 LKD(em->lock);
503 free(em); 516 free(em);
504
505 return EINA_TRUE;
506} 517}
507 518
508#if defined(_WIN32) || defined(__CYGWIN__) 519#if defined(_WIN32) || defined(__CYGWIN__)
@@ -712,18 +723,6 @@ evas_module_clean(void)
712 723
713static Eina_Prefix *pfx = NULL; 724static Eina_Prefix *pfx = NULL;
714 725
715static Eina_Bool
716_cb_mod_close(const Eina_Hash *hash EINA_UNUSED,
717 const void *key EINA_UNUSED,
718 void *data, void *fdata EINA_UNUSED)
719{
720 Evas_Module *em = data;
721
722 em->definition->func.close(em);
723 em->loaded = 0;
724 return EINA_TRUE;
725}
726
727/* will dlclose all the modules loaded and free all the structs */ 726/* will dlclose all the modules loaded and free all the structs */
728void 727void
729evas_module_shutdown(void) 728evas_module_shutdown(void)
@@ -734,13 +733,6 @@ evas_module_shutdown(void)
734 for (i = 0; evas_static_module[i].shutdown; ++i) 733 for (i = 0; evas_static_module[i].shutdown; ++i)
735 evas_static_module[i].shutdown(); 734 evas_static_module[i].shutdown();
736 735
737 eina_hash_foreach(evas_modules[EVAS_MODULE_TYPE_ENGINE], _cb_mod_close, NULL);
738 eina_hash_foreach(evas_modules[EVAS_MODULE_TYPE_IMAGE_LOADER], _cb_mod_close, NULL);
739 eina_hash_foreach(evas_modules[EVAS_MODULE_TYPE_IMAGE_SAVER], _cb_mod_close, NULL);
740 eina_hash_foreach(evas_modules[EVAS_MODULE_TYPE_OBJECT], _cb_mod_close, NULL);
741 eina_hash_foreach(evas_modules[EVAS_MODULE_TYPE_VG_LOADER], _cb_mod_close, NULL);
742 eina_hash_foreach(evas_modules[EVAS_MODULE_TYPE_VG_SAVER], _cb_mod_close, NULL);
743
744 eina_hash_free(evas_modules[EVAS_MODULE_TYPE_ENGINE]); 736 eina_hash_free(evas_modules[EVAS_MODULE_TYPE_ENGINE]);
745 evas_modules[EVAS_MODULE_TYPE_ENGINE] = NULL; 737 evas_modules[EVAS_MODULE_TYPE_ENGINE] = NULL;
746 eina_hash_free(evas_modules[EVAS_MODULE_TYPE_IMAGE_LOADER]); 738 eina_hash_free(evas_modules[EVAS_MODULE_TYPE_IMAGE_LOADER]);