plugin: Don't unload external plugins too early

Plugins may reference data structures allocated by each other.
They all need to be deinitialized first, only then it should be
safe to unload the libraries.
This commit is contained in:
Slava Monich 2018-07-20 20:35:23 +03:00 committed by Denis Kenzior
parent 3c10ae7fb3
commit 376af6c85c
1 changed files with 12 additions and 3 deletions

View File

@ -190,17 +190,26 @@ void __ofono_plugin_cleanup(void)
DBG("");
/*
* Terminate the plugins but don't unload the libraries yet.
* Plugins may reference data structures allocated by each other.
*/
for (list = plugins; list; list = list->next) {
struct ofono_plugin *plugin = list->data;
if (plugin->active == TRUE && plugin->desc->exit)
plugin->desc->exit();
}
/* Second pass - unload the libraries */
for (list = plugins; list; list = list->next) {
struct ofono_plugin *plugin = list->data;
if (plugin->handle)
dlclose(plugin->handle);
g_free(plugin);
}
g_slist_free(plugins);
/* Finally, free the memory */
g_slist_free_full(plugins, g_free);
plugins = NULL;
}