Skip to contentSkip to conversation

shared/gatt-client: Fix memory leak of ready callback

PATCH Applied Szymon Janc 1 participant 2 messages Dec 20, 2017 – Dec 21, 2017 Bluetooth drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 shared/gatt-client: Fix memory leak of ready callback

72 bytes in 3 blocks are definitely lost in loss record 161 of 244
at 0x4C2FB6B: malloc (vg_replace_malloc.c:299)
by 0x48D07D: btd_malloc (util.c:45)
by 0x493992: bt_gatt_client_ready_register (gatt-client.c:1924) by 0x472BD7: gatt_client_init (device.c:4785)
by 0x472BD7: device_attach_att (device.c:4919)
by 0x4740A2: att_connect_cb (device.c:4963)
by 0x445024: connect_cb (btio.c:232)
by 0x50CEBB6: g_main_context_dispatch (in /usr/lib64/libglib-2.0.so.0.5400.2) by 0x50CEF5F: ??? (in /usr/lib64/libglib-2.0.so.0.5400.2)
by 0x50CF271: g_main_loop_run (in /usr/lib64/libglib-2.0.so.0.5400.2) by 0x40BDE8: main (main.c:770)

---
 src/shared/gatt-client.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
src/shared/gatt-client.c +8 -1
index 4b3f553f1..8083ff719 100644
@@ -1934,7 +1934,14 @@ unsigned int bt_gatt_client_ready_register(struct bt_gatt_client *client,
 bool bt_gatt_client_ready_unregister(struct bt_gatt_client *client,
 						unsigned int id)
 {
-	return queue_remove(client->ready_cbs, UINT_TO_PTR(id));
+	struct ready_cb *ready = UINT_TO_PTR(id);
+
+	if (queue_remove(client->ready_cbs, ready)) {
+		ready_destroy(ready);
+		return true;
+	}
+
+	return false;
 }
 
 bool bt_gatt_client_set_service_changed(struct bt_gatt_client *client,
Signature · 1 line
2.14.3
author Applied
#1 lore raw
Quoted 27 lines · On Wednesday, 20 December 2017 21:44:15 CET Szymon Janc wrote:

72 bytes in 3 blocks are definitely lost in loss record 161 of 244
at 0x4C2FB6B: malloc (vg_replace_malloc.c:299)
by 0x48D07D: btd_malloc (util.c:45)
by 0x493992: bt_gatt_client_ready_register (gatt-client.c:1924) by 0x472BD7: gatt_client_init (device.c:4785)
by 0x472BD7: device_attach_att (device.c:4919)
by 0x4740A2: att_connect_cb (device.c:4963)
by 0x445024: connect_cb (btio.c:232)
by 0x50CEBB6: g_main_context_dispatch (in
/usr/lib64/libglib-2.0.so.0.5400.2) by 0x50CEF5F: ??? (in /usr/lib64/libglib-2.0.so.0.5400.2)
by 0x50CF271: g_main_loop_run (in /usr/lib64/libglib-2.0.so.0.5400.2) by 0x40BDE8: main (main.c:770)

---
 src/shared/gatt-client.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
src/shared/gatt-client.c +0 -0
index 4b3f553f1..8083ff719 100644
@@ -1934,7 +1934,14 @@ unsigned int bt_gatt_client_ready_register(struct

bt_gatt_client *client, bool bt_gatt_client_ready_unregister(struct bt_gatt_client *client, unsigned int id)
{

src/shared/gatt-client.c +1 -1
-	return queue_remove(client->ready_cbs, UINT_TO_PTR(id));
+	struct ready_cb *ready = UINT_TO_PTR(id);

src/shared/gatt-client.c unsigned int bt_gatt_client_ready_register(struct bt_gatt_client *client, · line 1947

Quoted 10 lines
src/shared/gatt-client.c +7 -0
+
+	if (queue_remove(client->ready_cbs, ready)) {
+		ready_destroy(ready);
+		return true;
+	}
+
+	return false;
 }
 
 bool bt_gatt_client_set_service_changed(struct bt_gatt_client *client,

Applied.

Signature · 2 lines
pozdrawiam
Szymon Janc