Skip to content

Commit

Permalink
refactor(core): always destroy plugin extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
andyholmes committed Dec 19, 2024
1 parent ae3a2e5 commit 8aff631
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 43 deletions.
6 changes: 6 additions & 0 deletions src/libvalent/core/valent-component-private.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
15 changes: 1 addition & 14 deletions src/libvalent/core/valent-component.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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);
}

Expand Down
17 changes: 1 addition & 16 deletions src/libvalent/device/valent-device-manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}

Expand Down
14 changes: 1 addition & 13 deletions src/libvalent/device/valent-device.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 8aff631

Please sign in to comment.