* [PATCH] android/gatt: Fix memory leak
@ 2014-12-19 13:50 Andrei Emeltchenko
2014-12-24 11:16 ` Szymon Janc
0 siblings, 1 reply; 4+ messages in thread
From: Andrei Emeltchenko @ 2014-12-19 13:50 UTC (permalink / raw)
To: linux-bluetooth
From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
---
android/gatt.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/android/gatt.c b/android/gatt.c
index 2534836..6248f07 100644
--- a/android/gatt.c
+++ b/android/gatt.c
@@ -6129,6 +6129,7 @@ static uint8_t find_info_handle(const uint8_t *cmd, uint16_t cmd_len,
int iterator = 0;
uint16_t start, end;
uint16_t len, queue_len;
+ uint8_t ret = 0;
DBG("");
@@ -6206,13 +6207,13 @@ static uint8_t find_info_handle(const uint8_t *cmd, uint16_t cmd_len,
ATT_FIND_INFO_RESP_FMT_128BIT, adl, rsp,
rsp_size);
if (!len)
- return ATT_ECODE_UNLIKELY;
+ ret = ATT_ECODE_UNLIKELY;
*length = len;
att_data_list_free(adl);
queue_destroy(temp, NULL);
- return 0;
+ return ret;
}
static uint8_t find_by_type_request(const uint8_t *cmd, uint16_t cmd_len,
--
2.1.0
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH] android/gatt: Fix memory leak
2014-12-19 13:50 [PATCH] android/gatt: Fix memory leak Andrei Emeltchenko
@ 2014-12-24 11:16 ` Szymon Janc
0 siblings, 0 replies; 4+ messages in thread
From: Szymon Janc @ 2014-12-24 11:16 UTC (permalink / raw)
To: Andrei Emeltchenko; +Cc: linux-bluetooth
Hi Andrei,
On Friday 19 of December 2014 15:50:20 Andrei Emeltchenko wrote:
> From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
>
> ---
> android/gatt.c | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/android/gatt.c b/android/gatt.c
> index 2534836..6248f07 100644
> --- a/android/gatt.c
> +++ b/android/gatt.c
> @@ -6129,6 +6129,7 @@ static uint8_t find_info_handle(const uint8_t *cmd,
> uint16_t cmd_len, int iterator = 0;
> uint16_t start, end;
> uint16_t len, queue_len;
> + uint8_t ret = 0;
>
> DBG("");
>
> @@ -6206,13 +6207,13 @@ static uint8_t find_info_handle(const uint8_t *cmd,
> uint16_t cmd_len, ATT_FIND_INFO_RESP_FMT_128BIT, adl, rsp,
> rsp_size);
> if (!len)
> - return ATT_ECODE_UNLIKELY;
> + ret = ATT_ECODE_UNLIKELY;
>
> *length = len;
> att_data_list_free(adl);
> queue_destroy(temp, NULL);
>
> - return 0;
> + return ret;
> }
>
> static uint8_t find_by_type_request(const uint8_t *cmd, uint16_t cmd_len,
Applied, thanks.
--
BR
Szymon Janc
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH] android/gatt: Fix memory leak
@ 2014-07-03 11:32 Andrei Emeltchenko
0 siblings, 0 replies; 4+ messages in thread
From: Andrei Emeltchenko @ 2014-07-03 11:32 UTC (permalink / raw)
To: linux-bluetooth
From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
Fixes clang warnings:
...
android/gatt.c:2823:1: warning: Potential leak of memory pointed to by
'cb_data'
...
---
android/gatt.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/android/gatt.c b/android/gatt.c
index d672bdb..9e23398 100644
--- a/android/gatt.c
+++ b/android/gatt.c
@@ -2957,7 +2957,8 @@ static void handle_client_write_characteristic(const void *buf, uint16_t len)
goto failed;
}
- if (cmd->write_type != GATT_WRITE_TYPE_NO_RESPONSE) {
+ if (cmd->write_type != GATT_WRITE_TYPE_NO_RESPONSE &&
+ cmd->write_type != GATT_WRITE_TYPE_SIGNED) {
cb_data = create_char_op_data(cmd->conn_id, &srvc->id, &ch->id,
cmd->srvc_id.is_primary);
if (!cb_data) {
--
1.9.1
^ permalink raw reply related [flat|nested] 4+ messages in thread* [PATCH] android/gatt: Fix memory leak
@ 2014-04-12 21:48 Lukasz Rymanowski
0 siblings, 0 replies; 4+ messages in thread
From: Lukasz Rymanowski @ 2014-04-12 21:48 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 243e02f..abec46b 100644
--- a/android/gatt.c
+++ b/android/gatt.c
@@ -388,6 +388,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;
@@ -395,6 +416,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);
@@ -654,27 +678,6 @@ done:
send_client_all_primary(gatt_status, dev->services, dev->conn_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 send_client_disconnect_notify(int32_t id, struct gatt_device *dev,
int32_t status)
{
--
1.8.4
^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2014-12-24 11:16 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-12-19 13:50 [PATCH] android/gatt: Fix memory leak Andrei Emeltchenko
2014-12-24 11:16 ` Szymon Janc
-- strict thread matches above, loose matches on Subject: below --
2014-07-03 11:32 Andrei Emeltchenko
2014-04-12 21:48 Lukasz Rymanowski
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).