gplugin/gplugin

unload plugins when the plugin manager is finalized.
bugfix/valgrind-catchup
2020-03-09, Gary Kramlich
59cd9964eace
Parents 566a52ac82ce
Children 43d6a4c53957
unload plugins when the plugin manager is finalized.
--- a/gplugin/gplugin-manager.c Mon Mar 09 21:33:40 2020 -0500
+++ b/gplugin/gplugin-manager.c Mon Mar 09 21:34:41 2020 -0500
@@ -206,6 +206,36 @@
return NULL;
}
+static void
+gplugin_manager_foreach_unload_plugin(
+ gpointer key,
+ gpointer value,
+ G_GNUC_UNUSED gpointer data)
+{
+ GList *l = NULL;
+ gchar *id = (gchar *)key;
+
+ for(l = (GList *)value; l; l = l->next) {
+ GPluginPlugin *plugin = GPLUGIN_PLUGIN(l->data);
+ GPluginLoader *loader = NULL;
+ GError *error = NULL;
+
+ if(gplugin_plugin_get_state(plugin) != GPLUGIN_PLUGIN_STATE_LOADED) {
+ continue;
+ }
+
+ loader = gplugin_plugin_get_loader(plugin);
+ if(!gplugin_loader_unload_plugin(loader, plugin, &error)) {
+ g_warning(
+ "failed to unload plugin with id %s: %s",
+ id,
+ error ? error->message : "unknown");
+ g_clear_error(&error);
+ }
+ g_object_unref(G_OBJECT(loader));
+ }
+}
+
/******************************************************************************
* Manager implementation
*****************************************************************************/
@@ -738,6 +768,7 @@
info = gplugin_plugin_get_info(plugin);
dependencies = gplugin_plugin_info_get_dependencies(info);
+ g_object_unref(G_OBJECT(info));
if(dependencies == NULL) {
return NULL;
@@ -797,14 +828,10 @@
g_slist_free_full(ret, g_object_unref);
- g_object_unref(G_OBJECT(info));
-
return NULL;
}
}
- g_object_unref(G_OBJECT(info));
-
return ret;
}
@@ -942,7 +969,7 @@
}
/******************************************************************************
- * Object Stuff
+ * GObject Implementation
*****************************************************************************/
static void
gplugin_manager_finalize(GObject *obj)
@@ -952,6 +979,12 @@
g_queue_free_full(manager->paths, g_free);
manager->paths = NULL;
+ /* unload all of the loaded plugins */
+ g_hash_table_foreach(
+ manager->plugins,
+ gplugin_manager_foreach_unload_plugin,
+ NULL);
+
/* free all the data in the plugins hash table and destroy it */
g_hash_table_foreach_remove(
manager->plugins,