From 376af6c85c14de83c2197a63e5a38c12ba3640c6 Mon Sep 17 00:00:00 2001 From: Slava Monich Date: Fri, 20 Jul 2018 20:35:23 +0300 Subject: [PATCH] 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. --- src/plugin.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/plugin.c b/src/plugin.c index 2c9c619a..924a45ec 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; }