linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] shared/gatt-client: Fix memory leak of ready callback
@ 2017-12-20 20:44 Szymon Janc
  2017-12-21  8:31 ` Szymon Janc
  0 siblings, 1 reply; 2+ messages in thread
From: Szymon Janc @ 2017-12-20 20:44 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Szymon Janc

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(-)

diff --git a/src/shared/gatt-client.c b/src/shared/gatt-client.c
index 4b3f553f1..8083ff719 100644
--- a/src/shared/gatt-client.c
+++ b/src/shared/gatt-client.c
@@ -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,
-- 
2.14.3


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

* Re: [PATCH] shared/gatt-client: Fix memory leak of ready callback
  2017-12-20 20:44 [PATCH] shared/gatt-client: Fix memory leak of ready callback Szymon Janc
@ 2017-12-21  8:31 ` Szymon Janc
  0 siblings, 0 replies; 2+ messages in thread
From: Szymon Janc @ 2017-12-21  8:31 UTC (permalink / raw)
  To: linux-bluetooth

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(-)
> 
> diff --git a/src/shared/gatt-client.c b/src/shared/gatt-client.c
> index 4b3f553f1..8083ff719 100644
> --- a/src/shared/gatt-client.c
> +++ b/src/shared/gatt-client.c
> @@ -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,

Applied.

-- 
pozdrawiam
Szymon Janc

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

end of thread, other threads:[~2017-12-21  8:31 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-12-20 20:44 [PATCH] shared/gatt-client: Fix memory leak of ready callback Szymon Janc
2017-12-21  8:31 ` Szymon Janc

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).