Linux bluetooth development
 help / color / mirror / Atom feed
* [PATCH v2] android/gatt: Fix memory leak
@ 2014-04-14  8:55 Lukasz Rymanowski
  2014-04-14  9:36 ` Szymon Janc
  0 siblings, 1 reply; 2+ messages in thread
From: Lukasz Rymanowski @ 2014-04-14  8:55 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: szymon.janc, Lukasz Rymanowski

It happens on daemon exit when connection is up.

295 (104 direct, 191 indirect) bytes in 1 blocks are definitely lost in
loss record 140 of 148
==25132==    at 0x4C2B6CD: malloc (in
/usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==25132==    by 0x4E7FBBD: g_try_malloc0 (in
/lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.4)
==25132==    by 0x437BF9: g_attrib_new (gattrib.c:495)
==25132==    by 0x42F45F: connect_cb (gatt.c:845)
==25132==    by 0x439DBA: connect_cb (btio.c:232)
==25132==    by 0x4E79D12: g_main_context_dispatch (in
/lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.4)
==25132==    by 0x4E7A05F: ??? (in
/lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.4)
==25132==    by 0x4E7A459: g_main_loop_run (in
/lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.4)
==25132==    by 0x4044FD: main (main.c:531)

This patch moves function connection_cleanup up in the file as this is
needed by destroy_device
---
 android/gatt.c | 45 ++++++++++++++++++++++++---------------------
 1 file changed, 24 insertions(+), 21 deletions(-)

diff --git a/android/gatt.c b/android/gatt.c
index 53131d4..004063c 100644
--- a/android/gatt.c
+++ b/android/gatt.c
@@ -395,6 +395,27 @@ static void unregister_notification(void *data)
 							notification->ind_id);
 }
 
+static void connection_cleanup(struct gatt_device *device)
+{
+	if (device->watch_id) {
+		g_source_remove(device->watch_id);
+		device->watch_id = 0;
+	}
+
+	if (device->att_io) {
+		g_io_channel_shutdown(device->att_io, FALSE, NULL);
+		g_io_channel_unref(device->att_io);
+		device->att_io = NULL;
+	}
+
+	if (device->attrib) {
+		GAttrib *attrib = device->attrib;
+		device->attrib = NULL;
+		g_attrib_cancel_all(attrib);
+		g_attrib_unref(attrib);
+	}
+}
+
 static void destroy_device(void *data)
 {
 	struct gatt_device *dev = data;
@@ -402,6 +423,9 @@ static void destroy_device(void *data)
 	if (!dev)
 		return;
 
+	if (dev->conn_id)
+		connection_cleanup(dev);
+
 	queue_destroy(dev->clients, NULL);
 	queue_destroy(dev->services, destroy_service);
 	free(dev);
@@ -499,27 +523,6 @@ failed:
 									status);
 }
 
-static void connection_cleanup(struct gatt_device *device)
-{
-	if (device->watch_id) {
-		g_source_remove(device->watch_id);
-		device->watch_id = 0;
-	}
-
-	if (device->att_io) {
-		g_io_channel_shutdown(device->att_io, FALSE, NULL);
-		g_io_channel_unref(device->att_io);
-		device->att_io = NULL;
-	}
-
-	if (device->attrib) {
-		GAttrib *attrib = device->attrib;
-		device->attrib = NULL;
-		g_attrib_cancel_all(attrib);
-		g_attrib_unref(attrib);
-	}
-}
-
 static void send_client_disconnect_notify(int32_t id, struct gatt_device *dev,
 								int32_t status)
 {
-- 
1.8.4


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v2] android/gatt: Fix memory leak
  2014-04-14  8:55 [PATCH v2] android/gatt: Fix memory leak Lukasz Rymanowski
@ 2014-04-14  9:36 ` Szymon Janc
  0 siblings, 0 replies; 2+ messages in thread
From: Szymon Janc @ 2014-04-14  9:36 UTC (permalink / raw)
  To: Lukasz Rymanowski; +Cc: linux-bluetooth

Hi Łukasz,

On Monday 14 of April 2014 10:55:14 Lukasz Rymanowski wrote:
> It happens on daemon exit when connection is up.
> 
> 295 (104 direct, 191 indirect) bytes in 1 blocks are definitely lost in
> loss record 140 of 148
> ==25132==    at 0x4C2B6CD: malloc (in
> /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
> ==25132==    by 0x4E7FBBD: g_try_malloc0 (in
> /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.4)
> ==25132==    by 0x437BF9: g_attrib_new (gattrib.c:495)
> ==25132==    by 0x42F45F: connect_cb (gatt.c:845)
> ==25132==    by 0x439DBA: connect_cb (btio.c:232)
> ==25132==    by 0x4E79D12: g_main_context_dispatch (in
> /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.4)
> ==25132==    by 0x4E7A05F: ??? (in
> /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.4)
> ==25132==    by 0x4E7A459: g_main_loop_run (in
> /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.4)
> ==25132==    by 0x4044FD: main (main.c:531)
> 
> This patch moves function connection_cleanup up in the file as this is
> needed by destroy_device
> ---
>  android/gatt.c | 45 ++++++++++++++++++++++++---------------------
>  1 file changed, 24 insertions(+), 21 deletions(-)

Patch applied, thanks.

-- 
Best regards, 
Szymon Janc

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2014-04-14  9:36 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-04-14  8:55 [PATCH v2] android/gatt: Fix memory leak Lukasz Rymanowski
2014-04-14  9:36 ` Szymon Janc

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox