libnm: disconnect signal from D-Bus proxies on dispose
Closes: #854810
Michael Biebl
7 years ago
0 | From: Beniamino Galvani <bgalvani@redhat.com> | |
1 | Date: Thu, 16 Feb 2017 18:48:38 +0100 | |
2 | Subject: libnm: disconnect signal from D-Bus proxies on dispose | |
3 | ||
4 | https://bugzilla.gnome.org/show_bug.cgi?id=778615 | |
5 | (cherry picked from commit 5ae3db75158b2a5d71ea7027fe12638a3d243a4e) | |
6 | (cherry picked from commit 0429753dab39c245f280c47ee269d88cf92d7061) | |
7 | --- | |
8 | libnm/nm-device.c | 2 ++ | |
9 | libnm/nm-object.c | 16 +++++++++++++++- | |
10 | 2 files changed, 17 insertions(+), 1 deletion(-) | |
11 | ||
12 | diff --git a/libnm/nm-device.c b/libnm/nm-device.c | |
13 | index 02b5cad..85cd060 100644 | |
14 | --- a/libnm/nm-device.c | |
15 | +++ b/libnm/nm-device.c | |
16 | @@ -297,6 +297,8 @@ dispose (GObject *object) | |
17 | g_clear_pointer (&priv->available_connections, g_ptr_array_unref); | |
18 | g_clear_pointer (&priv->lldp_neighbors, g_ptr_array_unref); | |
19 | ||
20 | + if (priv->proxy) | |
21 | + g_signal_handlers_disconnect_by_func (priv->proxy, device_state_reason_changed, object); | |
22 | g_clear_object (&priv->proxy); | |
23 | ||
24 | G_OBJECT_CLASS (nm_device_parent_class)->dispose (object); | |
25 | diff --git a/libnm/nm-object.c b/libnm/nm-object.c | |
26 | index 6a47c65..91ced0e 100644 | |
27 | --- a/libnm/nm-object.c | |
28 | +++ b/libnm/nm-object.c | |
29 | @@ -85,6 +85,7 @@ typedef struct { | |
30 | GError *reload_error; | |
31 | ||
32 | GSList *pending; /* ordered list of pending property updates. */ | |
33 | + GPtrArray *proxies; | |
34 | } NMObjectPrivate; | |
35 | ||
36 | enum { | |
37 | @@ -939,7 +940,7 @@ _nm_object_register_properties (NMObject *object, | |
38 | proxy = _nm_object_get_proxy (object, interface); | |
39 | g_signal_connect (proxy, "g-properties-changed", | |
40 | G_CALLBACK (properties_changed), object); | |
41 | - g_object_unref (proxy); | |
42 | + g_ptr_array_add (priv->proxies, proxy); | |
43 | ||
44 | instance = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); | |
45 | priv->property_tables = g_slist_prepend (priv->property_tables, instance); | |
46 | @@ -1188,6 +1189,7 @@ nm_object_async_initable_iface_init (GAsyncInitableIface *iface) | |
47 | static void | |
48 | nm_object_init (NMObject *object) | |
49 | { | |
50 | + NM_OBJECT_GET_PRIVATE (object)->proxies = g_ptr_array_new (); | |
51 | } | |
52 | ||
53 | static void | |
54 | @@ -1240,6 +1242,7 @@ static void | |
55 | dispose (GObject *object) | |
56 | { | |
57 | NMObjectPrivate *priv = NM_OBJECT_GET_PRIVATE (object); | |
58 | + guint i; | |
59 | ||
60 | nm_clear_g_source (&priv->notify_id); | |
61 | ||
62 | @@ -1251,6 +1254,17 @@ dispose (GObject *object) | |
63 | g_clear_object (&priv->object); | |
64 | g_clear_object (&priv->object_manager); | |
65 | ||
66 | + if (priv->proxies) { | |
67 | + for (i = 0; i < priv->proxies->len; i++) { | |
68 | + g_signal_handlers_disconnect_by_func (priv->proxies->pdata[i], | |
69 | + properties_changed, | |
70 | + object); | |
71 | + g_object_unref (priv->proxies->pdata[i]); | |
72 | + } | |
73 | + g_ptr_array_free (priv->proxies, TRUE); | |
74 | + priv->proxies = NULL; | |
75 | + } | |
76 | + | |
77 | G_OBJECT_CLASS (nm_object_parent_class)->dispose (object); | |
78 | } | |
79 |