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.
---
src/plugin.c | 15 ++++++++++++---
1 file changed, 12 insertions(+), 3 deletions(-)
diff --git a/src/plugin.c b/src/plugin.c
index 2c9c619..924a45e 100644
--- a/src/plugin.c
+++ b/src/plugin.c
@@ -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;
}
--
1.9.1
_______________________________________________
ofono mailing list
[email protected]
https://lists.ofono.org/mailman/listinfo/ofono