[gnome-bluetooth/gnome-3-2] lib: Do not leak proxies for detectable interfaces of devices



commit f591ab0c2279425f8561954571c3cdf0c454ead1
Author: Vincent Untz <vuntz gnome org>
Date:   Tue Oct 11 09:46:52 2011 +0200

    lib: Do not leak proxies for detectable interfaces of devices
    
    This avoids signals that will cause crashes.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=654172

 lib/bluetooth-client.c |   14 ++++++++++++++
 1 files changed, 14 insertions(+), 0 deletions(-)
---
diff --git a/lib/bluetooth-client.c b/lib/bluetooth-client.c
index d7af201..e2f66c7 100644
--- a/lib/bluetooth-client.c
+++ b/lib/bluetooth-client.c
@@ -103,6 +103,7 @@ struct _BluetoothClientPrivate {
 	DBusGProxy *manager;
 	GtkTreeStore *store;
 	GtkTreeRowReference *default_adapter;
+	GSList *horrible_workaround_for_leaked_ifaces;
 };
 
 enum {
@@ -266,6 +267,7 @@ device_services_changed (DBusGProxy *iface, const char *property,
 static GHashTable *
 device_list_nodes (DBusGProxy *device, BluetoothClient *client, gboolean connect_signal)
 {
+	BluetoothClientPrivate *priv = BLUETOOTH_CLIENT_GET_PRIVATE(client);
 	GHashTable *table;
 	guint i;
 
@@ -333,6 +335,8 @@ device_list_nodes (DBusGProxy *device, BluetoothClient *client, gboolean connect
 				dbus_g_proxy_connect_signal(iface, "PropertyChanged",
 							    G_CALLBACK(device_services_changed), client, NULL);
 			}
+
+			priv->horrible_workaround_for_leaked_ifaces = g_slist_append (priv->horrible_workaround_for_leaked_ifaces, iface);
 		}
 	}
 
@@ -1055,6 +1059,7 @@ disconnect_from_proxy_helper (GtkTreeModel *model,
 static void bluetooth_client_finalize(GObject *client)
 {
 	BluetoothClientPrivate *priv = BLUETOOTH_CLIENT_GET_PRIVATE(client);
+	GSList *l;
 
 	DBG("client %p", client);
 
@@ -1079,6 +1084,15 @@ static void bluetooth_client_finalize(GObject *client)
 	if (priv->default_adapter)
 		gtk_tree_row_reference_free (priv->default_adapter);
 
+	for (l = priv->horrible_workaround_for_leaked_ifaces; l != NULL; l = l->next) {
+		DBusGProxy *iface = l->data;
+
+		g_signal_handlers_disconnect_by_func(iface,
+					device_services_changed, client);
+		g_object_unref (iface);
+	}
+	g_slist_free (priv->horrible_workaround_for_leaked_ifaces);
+
 	G_OBJECT_CLASS(bluetooth_client_parent_class)->finalize(client);
 }
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]