2014-01-30 13:23:43

by Andrei Emeltchenko

[permalink] [raw]
Subject: [PATCH] android/avrcp: Close AVRCP channel on error

From: Andrei Emeltchenko <[email protected]>

This fixes resource leak.
---
android/avrcp.c | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/android/avrcp.c b/android/avrcp.c
index 485b485..ef833df 100644
--- a/android/avrcp.c
+++ b/android/avrcp.c
@@ -248,13 +248,13 @@ bool bt_avrcp_register(const bdaddr_t *addr)
rec = avrcp_record();
if (!rec) {
error("Failed to allocate AVRCP record");
- return false;
+ goto fail;
}

if (bt_adapter_add_record(rec, 0) < 0) {
error("Failed to register AVRCP record");
sdp_record_free(rec);
- return false;
+ goto fail;
}
record_id = rec->handle;

@@ -262,6 +262,12 @@ bool bt_avrcp_register(const bdaddr_t *addr)
G_N_ELEMENTS(cmd_handlers));

return true;
+fail:
+ g_io_channel_shutdown(server, TRUE, NULL);
+ g_io_channel_unref(server);
+ server = NULL;
+
+ return false;
}

void bt_avrcp_unregister(void)
--
1.8.3.2



2014-02-02 16:05:55

by Luiz Augusto von Dentz

[permalink] [raw]
Subject: Re: [PATCH] android/avrcp: Close AVRCP channel on error

Hi Andrei,

On Thu, Jan 30, 2014 at 5:23 AM, Andrei Emeltchenko
<[email protected]> wrote:
> From: Andrei Emeltchenko <[email protected]>
>
> This fixes resource leak.
> ---
> android/avrcp.c | 10 ++++++++--
> 1 file changed, 8 insertions(+), 2 deletions(-)
>
> diff --git a/android/avrcp.c b/android/avrcp.c
> index 485b485..ef833df 100644
> --- a/android/avrcp.c
> +++ b/android/avrcp.c
> @@ -248,13 +248,13 @@ bool bt_avrcp_register(const bdaddr_t *addr)
> rec = avrcp_record();
> if (!rec) {
> error("Failed to allocate AVRCP record");
> - return false;
> + goto fail;
> }
>
> if (bt_adapter_add_record(rec, 0) < 0) {
> error("Failed to register AVRCP record");
> sdp_record_free(rec);
> - return false;
> + goto fail;
> }
> record_id = rec->handle;
>
> @@ -262,6 +262,12 @@ bool bt_avrcp_register(const bdaddr_t *addr)
> G_N_ELEMENTS(cmd_handlers));
>
> return true;
> +fail:
> + g_io_channel_shutdown(server, TRUE, NULL);
> + g_io_channel_unref(server);
> + server = NULL;
> +
> + return false;
> }
>
> void bt_avrcp_unregister(void)
> --
> 1.8.3.2

Applied, thanks.


--
Luiz Augusto von Dentz