2014-10-28 13:28:30

by Andrei Emeltchenko

[permalink] [raw]
Subject: [PATCH] hfp: Fix memory leak

From: Andrei Emeltchenko <[email protected]>

Free fmt allocated by asprintf().
---
src/shared/hfp.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/shared/hfp.c b/src/shared/hfp.c
index 22e9622..9a66ed2 100644
--- a/src/shared/hfp.c
+++ b/src/shared/hfp.c
@@ -1321,8 +1321,10 @@ bool hfp_hf_send_command(struct hfp_hf *hfp, hfp_response_func_t resp_cb,
return false;

cmd = new0(struct cmd_response, 1);
- if (!cmd)
+ if (!cmd) {
+ free(fmt);
return false;
+ }

va_start(ap, format);
len = ringbuf_vprintf(hfp->write_buf, fmt, ap);
--
1.9.1



2014-10-30 09:30:28

by Szymon Janc

[permalink] [raw]
Subject: Re: [PATCH] hfp: Fix memory leak

Hi Andrei,

On Tuesday 28 of October 2014 15:28:30 Andrei Emeltchenko wrote:
> From: Andrei Emeltchenko <[email protected]>
>
> Free fmt allocated by asprintf().
> ---
> src/shared/hfp.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/src/shared/hfp.c b/src/shared/hfp.c
> index 22e9622..9a66ed2 100644
> --- a/src/shared/hfp.c
> +++ b/src/shared/hfp.c
> @@ -1321,8 +1321,10 @@ bool hfp_hf_send_command(struct hfp_hf *hfp,
> hfp_response_func_t resp_cb, return false;
>
> cmd = new0(struct cmd_response, 1);
> - if (!cmd)
> + if (!cmd) {
> + free(fmt);
> return false;
> + }
>
> va_start(ap, format);
> len = ringbuf_vprintf(hfp->write_buf, fmt, ap);

Patch applied after fixing commit prefix, thanks.

--
BR
Szymon Janc