[gnome-bluetooth] Fix memleaks of the Services hashtable data



commit 6802a7d83521ea9266456ad415492ca46bcf0105
Author: Bastien Nocera <hadess hadess net>
Date:   Thu May 14 10:42:15 2009 +0100

    Fix memleaks of the Services hashtable data
    
    Spotted by Dan Williams. Thanks!
---
 applet/main.c             |    2 ++
 common/bluetooth-client.c |   13 ++++++++++++-
 common/test-client.c      |    2 ++
 3 files changed, 16 insertions(+), 1 deletions(-)

diff --git a/applet/main.c b/applet/main.c
index 9a93bfb..7ef7a84 100644
--- a/applet/main.c
+++ b/applet/main.c
@@ -639,6 +639,8 @@ update_device_list (GtkTreeIter *parent)
 		if (proxy != NULL)
 			g_object_unref (proxy);
 
+		if (table != NULL)
+			g_hash_table_unref (table);
 		g_free (alias);
 		g_free (address);
 		cont = gtk_tree_model_iter_next (devices_model, &iter);
diff --git a/common/bluetooth-client.c b/common/bluetooth-client.c
index 00cb4f8..e85ca46 100644
--- a/common/bluetooth-client.c
+++ b/common/bluetooth-client.c
@@ -535,6 +535,8 @@ static void device_changed(DBusGProxy *device, const char *property,
 		gtk_tree_store_set(priv->store, &iter,
 				   BLUETOOTH_COLUMN_SERVICES, services,
 				   BLUETOOTH_COLUMN_UUIDS, uuids, -1);
+		if (services != NULL)
+			g_hash_table_unref (services);
 		g_strfreev (uuids);
 	}
 }
@@ -555,6 +557,8 @@ static void add_device(DBusGProxy *adapter, GtkTreeIter *parent,
 	GtkTreeIter iter;
 	gboolean cont;
 
+	services = NULL;
+
 	if (hash == NULL) {
 		device = dbus_g_proxy_new_from_proxy(adapter,
 						BLUEZ_DEVICE_INTERFACE, path);
@@ -665,6 +669,8 @@ done:
 		g_object_unref(device);
 	}
 	g_strfreev (uuids);
+	if (services)
+		g_hash_table_unref (services);
 }
 
 static void device_found(DBusGProxy *adapter, const char *address,
@@ -1458,6 +1464,7 @@ gboolean bluetooth_client_connect_service(BluetoothClient *client,
 			break;
 		}
 	}
+	g_hash_table_unref (table);
 
 	if (iface_name == NULL) {
 		g_printerr("No supported services on the '%s' device\n", device);
@@ -1571,8 +1578,11 @@ gboolean bluetooth_client_disconnect_service (BluetoothClient *client,
 			   BLUETOOTH_COLUMN_PROXY, &proxy,
 			   BLUETOOTH_COLUMN_SERVICES, &table,
 			   -1);
-	if (proxy == NULL)
+	if (proxy == NULL) {
+		if (table != NULL)
+			g_hash_table_unref (table);
 		return FALSE;
+	}
 
 	conndata = g_new0 (ConnectData, 1);
 
@@ -1587,6 +1597,7 @@ gboolean bluetooth_client_disconnect_service (BluetoothClient *client,
 		DBusGProxy *service;
 
 		conndata->services = g_hash_table_get_keys (table);
+		g_hash_table_unref (table);
 		conndata->services = g_list_sort (conndata->services, (GCompareFunc) rev_sort_services);
 
 		service = dbus_g_proxy_new_from_proxy (priv->manager,
diff --git a/common/test-client.c b/common/test-client.c
index 22cf197..a948738 100644
--- a/common/test-client.c
+++ b/common/test-client.c
@@ -119,6 +119,8 @@ static void services_to_text(GtkTreeViewColumn *column, GtkCellRenderer *cell,
 	g_hash_table_foreach (services, (GHFunc) services_foreach, str);
 	g_object_set(cell, "text", str->str, NULL);
 	g_string_free (str, TRUE);
+
+	g_hash_table_unref (services);
 }
 
 static void uuids_to_text(GtkTreeViewColumn *column, GtkCellRenderer *cell,



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