[glib/th/gdbus-slice-alloc: 1/11] gdbus: refactor duplicate code for freeing FilterData
- From: Thomas Haller <thaller src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib/th/gdbus-slice-alloc: 1/11] gdbus: refactor duplicate code for freeing FilterData
- Date: Mon, 29 Mar 2021 06:28:19 +0000 (UTC)
commit ad701cfe866d240bdea0fe015c7a5a94c9e15281
Author: Thomas Haller <thaller redhat com>
Date: Sun Mar 28 08:53:57 2021 +0200
gdbus: refactor duplicate code for freeing FilterData
gio/gdbusconnection.c | 44 ++++++++++++++++++++++----------------------
1 file changed, 22 insertions(+), 22 deletions(-)
---
diff --git a/gio/gdbusconnection.c b/gio/gdbusconnection.c
index acaeb97fe..bb1c735b9 100644
--- a/gio/gdbusconnection.c
+++ b/gio/gdbusconnection.c
@@ -2202,6 +2202,24 @@ typedef struct
GMainContext *context;
} FilterData;
+static void
+filter_data_destroy (FilterData *filter, gboolean notify_sync)
+{
+ if (notify_sync)
+ {
+ if (filter->user_data_free_func != NULL)
+ filter->user_data_free_func (filter->user_data);
+ }
+ else
+ {
+ call_destroy_notify (filter->context,
+ filter->user_data_free_func,
+ filter->user_data);
+ }
+ g_main_context_unref (filter->context);
+ g_free (filter);
+}
+
/* requires CONNECTION_LOCK */
static FilterData **
copy_filter_list (GPtrArray *filters)
@@ -2230,13 +2248,7 @@ free_filter_list (FilterData **filters)
{
filters[n]->ref_count--;
if (filters[n]->ref_count == 0)
- {
- call_destroy_notify (filters[n]->context,
- filters[n]->user_data_free_func,
- filters[n]->user_data);
- g_main_context_unref (filters[n]->context);
- g_free (filters[n]);
- }
+ filter_data_destroy (filters[n], FALSE);
}
g_free (filters);
}
@@ -3179,16 +3191,9 @@ static void
purge_all_filters (GDBusConnection *connection)
{
guint n;
- for (n = 0; n < connection->filters->len; n++)
- {
- FilterData *data = connection->filters->pdata[n];
- call_destroy_notify (data->context,
- data->user_data_free_func,
- data->user_data);
- g_main_context_unref (data->context);
- g_free (data);
- }
+ for (n = 0; n < connection->filters->len; n++)
+ filter_data_destroy (connection->filters->pdata[n], FALSE);
}
/**
@@ -3238,12 +3243,7 @@ g_dbus_connection_remove_filter (GDBusConnection *connection,
/* do free without holding lock */
if (to_destroy != NULL)
- {
- if (to_destroy->user_data_free_func != NULL)
- to_destroy->user_data_free_func (to_destroy->user_data);
- g_main_context_unref (to_destroy->context);
- g_free (to_destroy);
- }
+ filter_data_destroy (to_destroy, TRUE);
else if (!found)
{
g_warning ("g_dbus_connection_remove_filter: No filter found for filter_id %d", filter_id);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]