[PATCH] hfp: Fix memory leak when listing bluetooth devices

Vinicius Costa Gomes vinicius.gomes at openbossa.org
Fri Feb 5 15:06:47 PST 2010


---
 plugins/hfp.c |   10 +++++++---
 1 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/plugins/hfp.c b/plugins/hfp.c
index fe7b78b..f235253 100644
--- a/plugins/hfp.c
+++ b/plugins/hfp.c
@@ -547,7 +547,7 @@ static void parse_get_properties(DBusMessage *reply, const char *device)
 static void get_properties_cb(DBusPendingCall *call, gpointer user_data)
 {
 	DBusMessage *reply;
-	const char *device = user_data;
+	char *device = user_data;
 
 	reply = dbus_pending_call_steal_reply(call);
 
@@ -567,6 +567,7 @@ static void get_properties_cb(DBusPendingCall *call, gpointer user_data)
 	parse_get_properties(reply, device);
 
 done:
+	g_free(device);
 	dbus_message_unref(reply);
 }
 
@@ -574,7 +575,7 @@ static void list_devices_cb(DBusPendingCall *call, gpointer user_data)
 {
 	DBusError err;
 	DBusMessage *reply;
-	const char **device = NULL;
+	char **device = NULL;
 	int num, ret, i;
 
 	reply = dbus_pending_call_steal_reply(call);
@@ -607,11 +608,14 @@ static void list_devices_cb(DBusPendingCall *call, gpointer user_data)
 				BLUEZ_DEVICE_INTERFACE, "GetProperties",
 				get_properties_cb, (void *)device[i],
 				DBUS_TYPE_INVALID);
-		if (ret < 0)
+		if (ret < 0) {
+			g_free(device[i]);
 			ofono_error("GetProperties failed(%d)", ret);
+		}
 	}
 
 done:
+	g_free(device);
 	dbus_message_unref(reply);
 }
 
-- 
1.6.6.1



More information about the ofono mailing list