2017-06-21 10:07:19

by ERAMOTO Masaya

[permalink] [raw]
Subject: [PATCH BlueZ] client: Fix memory leak due to the option to register an agent

When bluetoothctl runs with the command line option "-a <capability>", it
does not free the variable auto_register_agent registering the initial
agent and allocates new memory for it.

This frees the allocated memory before allocating new memory.
(The related commit id is 6db3470c2ea161b4b808ad1fc80dfd7e014fd359.)

---
client/main.c | 1 +
1 file changed, 1 insertion(+)

diff --git a/client/main.c b/client/main.c
index 2f269af..9b01dfb 100644
--- a/client/main.c
+++ b/client/main.c
@@ -2358,6 +2358,7 @@ static gboolean parse_agent(const char *key, const char *value,
if (!value)
return FALSE;

+ g_free(auto_register_agent);
auto_register_agent = g_strdup(value);

return TRUE;
--
2.7.4



2017-07-07 07:44:40

by Luiz Augusto von Dentz

[permalink] [raw]
Subject: Re: [PATCH BlueZ] client: Fix memory leak due to the option to register an agent

Hi Eramoto,

On Tue, Jul 4, 2017 at 10:21 AM, ERAMOTO Masaya
<[email protected]> wrote:
> Hi Luiz,
>
> Would you apply my patch to git master branch if there are not any proble=
ms?
> I confirmed that it was applied to the latest master branch with no probl=
em.
>
> Regards,
> Eramoto
>
> On 2017=E5=B9=B406=E6=9C=8821=E6=97=A5 19:07, ERAMOTO Masaya wrote:
>> When bluetoothctl runs with the command line option "-a <capability>", i=
t
>> does not free the variable auto_register_agent registering the initial
>> agent and allocates new memory for it.
>>
>> This frees the allocated memory before allocating new memory.
>> (The related commit id is 6db3470c2ea161b4b808ad1fc80dfd7e014fd359.)
>>
>> ---
>> client/main.c | 1 +
>> 1 file changed, 1 insertion(+)
>>
>> diff --git a/client/main.c b/client/main.c
>> index 2f269af..9b01dfb 100644
>> --- a/client/main.c
>> +++ b/client/main.c
>> @@ -2358,6 +2358,7 @@ static gboolean parse_agent(const char *key, const=
char *value,
>> if (!value)
>> return FALSE;
>>
>> + g_free(auto_register_agent);
>> auto_register_agent =3D g_strdup(value);
>>
>> return TRUE;
>>

Applied, thanks.

--=20
Luiz Augusto von Dentz

2017-07-04 07:21:10

by ERAMOTO Masaya

[permalink] [raw]
Subject: Re: [PATCH BlueZ] client: Fix memory leak due to the option to register an agent

Hi Luiz,

Would you apply my patch to git master branch if there are not any problems?
I confirmed that it was applied to the latest master branch with no problem.

Regards,
Eramoto

On 2017年06月21日 19:07, ERAMOTO Masaya wrote:
> When bluetoothctl runs with the command line option "-a <capability>", it
> does not free the variable auto_register_agent registering the initial
> agent and allocates new memory for it.
>
> This frees the allocated memory before allocating new memory.
> (The related commit id is 6db3470c2ea161b4b808ad1fc80dfd7e014fd359.)
>
> ---
> client/main.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/client/main.c b/client/main.c
> index 2f269af..9b01dfb 100644
> --- a/client/main.c
> +++ b/client/main.c
> @@ -2358,6 +2358,7 @@ static gboolean parse_agent(const char *key, const char *value,
> if (!value)
> return FALSE;
>
> + g_free(auto_register_agent);
> auto_register_agent = g_strdup(value);
>
> return TRUE;
>