gplugin/gplugin

Fix a bunch of leaks in the the manager and the native loader
bugfix/valgrind-catchup
2020-03-09, Gary Kramlich
cb926f728b2e
Parents 80bb20cbb820
Children f85b91d2eff1
Fix a bunch of leaks in the the manager and the native loader
--- a/gplugin/gplugin-manager.c Mon Mar 09 23:18:47 2020 -0500
+++ b/gplugin/gplugin-manager.c Mon Mar 09 23:19:03 2020 -0500
@@ -509,14 +509,11 @@
manager->loaders_by_extension,
e->extension);
for(; l; l = l->next) {
- if(!l->data)
+ if(!GPLUGIN_IS_LOADER(l->data)) {
continue;
+ }
loader = GPLUGIN_LOADER(l->data);
- if(!GPLUGIN_IS_LOADER(loader)) {
- loader = NULL;
- continue;
- }
/* Try to probe the plugin with the current loader */
plugin =
@@ -525,7 +522,7 @@
/* Check the GError, if it's set, output its message and
* try the next loader.
*/
- if(plugin == NULL || error) {
+ if(error) {
errors++;
error_message = g_strdup_printf(
@@ -587,8 +584,12 @@
error_message = g_strdup_printf(
_("Plugin %s has a NULL id."),
real_filename);
+ g_free(real_filename);
+ g_object_unref(G_OBJECT(info));
+
error_messages =
g_list_prepend(error_messages, error_message);
+
continue;
}
@@ -658,6 +659,11 @@
}
g_object_unref(G_OBJECT(info));
+
+ /* since the plugin is now stored in our hash tables we
+ * need to remove this function's reference to it.
+ */
+ g_object_unref(G_OBJECT(plugin));
}
g_free(filename);
@@ -854,12 +860,15 @@
/* now try to get the plugin info from the plugin */
info = gplugin_plugin_get_info(plugin);
if(info == NULL) {
+ gchar *filename = gplugin_plugin_get_filename(plugin);
+
g_set_error(
error,
GPLUGIN_DOMAIN,
0,
_("Plugin %s did not return value plugin info"),
- gplugin_plugin_get_filename(plugin));
+ filename);
+ g_free(filename);
gplugin_plugin_set_state(plugin, GPLUGIN_PLUGIN_STATE_LOAD_FAILED);
@@ -878,13 +887,16 @@
loader = gplugin_plugin_get_loader(plugin);
if(!GPLUGIN_IS_LOADER(loader)) {
+ gchar *filename = gplugin_plugin_get_filename(plugin);
+
g_set_error(
error,
GPLUGIN_DOMAIN,
0,
_("The loader for %s is not a loader. This "
"should not happened!"),
- gplugin_plugin_get_filename(plugin));
+ filename);
+ g_free(filename);
gplugin_plugin_set_state(plugin, GPLUGIN_PLUGIN_STATE_LOAD_FAILED);
--- a/gplugin/gplugin-native-loader.c Mon Mar 09 23:18:47 2020 -0500
+++ b/gplugin/gplugin-native-loader.c Mon Mar 09 23:19:03 2020 -0500
@@ -241,9 +241,6 @@
return NULL;
}
- /* claim ownership of the info object */
- g_object_ref_sink(G_OBJECT(info));
-
/* now create the actual plugin instance */
/* clang-format off */
plugin = g_object_new(
@@ -261,6 +258,7 @@
g_object_unref(G_OBJECT(info));
if(!GPLUGIN_IS_NATIVE_PLUGIN(plugin)) {
+ g_module_close(module);
g_set_error_literal(
error,
GPLUGIN_DOMAIN,
@@ -311,10 +309,12 @@
/* validate the function */
if(func == NULL) {
- const char *filename = gplugin_plugin_get_filename(plugin);
+ gchar *filename = gplugin_plugin_get_filename(plugin);
g_warning(_("unload function for %s is NULL"), filename);
+ g_free(filename);
+
return FALSE;
}
--- a/gplugin/gplugin-native-plugin.c Mon Mar 09 23:18:47 2020 -0500
+++ b/gplugin/gplugin-native-plugin.c Mon Mar 09 23:19:03 2020 -0500
@@ -196,6 +196,8 @@
g_clear_object(&plugin->loader);
g_clear_object(&plugin->info);
+ g_module_close(plugin->module);
+
G_OBJECT_CLASS(gplugin_native_plugin_parent_class)->finalize(obj);
}