diff options
author | Jean-Philippe Andre <jp.andre@samsung.com> | 2017-02-21 14:46:02 +0900 |
---|---|---|
committer | Jean-Philippe Andre <jp.andre@samsung.com> | 2017-02-21 15:15:51 +0900 |
commit | 3cb6d55ef0b1526062b1a444b260104b4fce069d (patch) | |
tree | be47d1fab2a562ef4bebe7fecf64a03c58a2f235 /src/lib | |
parent | db71d94173c61feb9cb91636d6244721190c19b4 (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')
-rw-r--r-- | src/lib/evas/file/evas_module.c | 52 |
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 | ||
350 | static 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 */ |
352 | void | 354 | void |
@@ -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 | |||
498 | static 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 | ||
713 | static Eina_Prefix *pfx = NULL; | 724 | static Eina_Prefix *pfx = NULL; |
714 | 725 | ||
715 | static 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 */ |
728 | void | 727 | void |
729 | evas_module_shutdown(void) | 728 | evas_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]); |