From 8aff631325f1914964a3bc9c1b110f005f9ee5b1 Mon Sep 17 00:00:00 2001 From: Andy Holmes Date: Wed, 18 Dec 2024 12:20:28 -0800 Subject: [PATCH] refactor(core): always destroy plugin extensions --- src/libvalent/core/valent-component-private.h | 6 ++++++ src/libvalent/core/valent-component.c | 15 +-------------- src/libvalent/device/valent-device-manager.c | 17 +---------------- src/libvalent/device/valent-device.c | 14 +------------- 4 files changed, 9 insertions(+), 43 deletions(-) diff --git a/src/libvalent/core/valent-component-private.h b/src/libvalent/core/valent-component-private.h index f063532f38..6032c37df2 100644 --- a/src/libvalent/core/valent-component-private.h +++ b/src/libvalent/core/valent-component-private.h @@ -103,6 +103,12 @@ valent_plugin_free (gpointer data) g_cancellable_cancel (plugin->cancellable); g_signal_handlers_disconnect_by_data (plugin->settings, plugin); + if (VALENT_IS_OBJECT (plugin->extension)) + { + valent_object_destroy (VALENT_OBJECT (plugin->extension)); + g_clear_object (&plugin->extension); + } + plugin->parent = NULL; g_clear_object (&plugin->info); g_clear_object (&plugin->cancellable); diff --git a/src/libvalent/core/valent-component.c b/src/libvalent/core/valent-component.c index 2da2f3896c..ce09d4ae3c 100644 --- a/src/libvalent/core/valent-component.c +++ b/src/libvalent/core/valent-component.c @@ -57,19 +57,6 @@ typedef enum { static GParamSpec *properties[PROP_PRIMARY_ADAPTER + 1] = { NULL, }; - -static void -component_plugin_free (gpointer data) -{ - ValentPlugin *plugin = data; - - if (plugin->extension != NULL) - valent_object_destroy (VALENT_OBJECT (plugin->extension)); - - g_clear_pointer (&plugin, valent_plugin_free); -} - - static int64_t _peas_plugin_info_get_priority (PeasPluginInfo *info, const char *key) @@ -643,7 +630,7 @@ valent_component_init (ValentComponent *self) { ValentComponentPrivate *priv = valent_component_get_instance_private (self); - priv->plugins = g_hash_table_new_full (NULL, NULL, NULL, component_plugin_free); + priv->plugins = g_hash_table_new_full (NULL, NULL, NULL, valent_plugin_free); priv->items = g_ptr_array_new_with_free_func (g_object_unref); } diff --git a/src/libvalent/device/valent-device-manager.c b/src/libvalent/device/valent-device-manager.c index 5a7ed760c1..1da2375700 100644 --- a/src/libvalent/device/valent-device-manager.c +++ b/src/libvalent/device/valent-device-manager.c @@ -216,20 +216,6 @@ valent_device_manager_export_device (ValentDeviceManager *self, /* * Channel Services */ -static void -manager_plugin_free (gpointer data) -{ - ValentPlugin *plugin = data; - - if (plugin->extension != NULL) - { - g_signal_handlers_disconnect_by_data (plugin->extension, plugin->parent); - valent_object_destroy (VALENT_OBJECT (plugin->extension)); - } - - g_clear_pointer (&plugin, valent_plugin_free); -} - static gboolean valent_device_manager_check_device (ValentDeviceManager *self, ValentDevice *device) @@ -357,7 +343,6 @@ valent_device_manager_disable_plugin (ValentDeviceManager *self, if (plugin->extension != NULL) { - g_signal_handlers_disconnect_by_data (plugin->extension, self); valent_object_destroy (VALENT_OBJECT (plugin->extension)); g_clear_object (&plugin->extension); } @@ -884,7 +869,7 @@ valent_device_manager_init (ValentDeviceManager *self) self->context = valent_context_new (NULL, NULL, NULL); self->devices = g_ptr_array_new_with_free_func (g_object_unref); self->exports = g_hash_table_new_full (NULL, NULL, NULL, device_export_free); - self->plugins = g_hash_table_new_full (NULL, NULL, NULL, manager_plugin_free); + self->plugins = g_hash_table_new_full (NULL, NULL, NULL, valent_plugin_free); self->plugins_context = valent_context_new (self->context, "network", NULL); } diff --git a/src/libvalent/device/valent-device.c b/src/libvalent/device/valent-device.c index 4e3668ce9a..7d64f794e9 100644 --- a/src/libvalent/device/valent-device.c +++ b/src/libvalent/device/valent-device.c @@ -190,18 +190,6 @@ g_action_group_iface_init (GActionGroupInterface *iface) /* * Private plugin methods */ -static void -device_plugin_free (gpointer data) -{ - ValentPlugin *plugin = data; - - /* `::action-removed` needs to be emitted before the plugin is freed */ - if (plugin->extension != NULL) - valent_object_destroy (VALENT_OBJECT (plugin->extension)); - - g_clear_pointer (&plugin, valent_plugin_free); -} - static void on_plugin_action_added (GActionGroup *action_group, const char *action_name, @@ -980,7 +968,7 @@ valent_device_init (ValentDevice *self) GSimpleAction *action = NULL; /* Plugins */ - self->plugins = g_hash_table_new_full (NULL, NULL, NULL, device_plugin_free); + self->plugins = g_hash_table_new_full (NULL, NULL, NULL, valent_plugin_free); self->handlers = g_hash_table_new_full (g_str_hash, g_str_equal, g_free,