[PATCH v2] malloc: fix memleak in function muntrace
Florian Weimer
fw@deneb.enyo.de
Mon Apr 20 14:50:29 GMT 2020
* chenzefeng:
> when we call functons as follow:
> mtrace();
> ...
> muntrace();
> It would cause memleak, for the mtrace malloc some memory:
> mtd = malloc(TRACE_BUFFER_SIZE);
> and it would not be free. Therefor it should be freed in muntrace.
>
> Signed-off-by: chenzefeng <chenzefeng2@huawei.com>
glibc uses copyright assignment to the FSF for contributions, and not
the DCO.
I trust this contribution is covered by Huawei's copyright assignment?
> ---
> malloc/mtrace.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/malloc/mtrace.c b/malloc/mtrace.c
> index 7e7719df97..ab65ebe764 100644
> --- a/malloc/mtrace.c
> +++ b/malloc/mtrace.c
> @@ -365,4 +365,6 @@ muntrace (void)
>
> fprintf (f, "= End\n");
> fclose (f);
> + if (malloc_trace_buffer != NULL)
> + free (malloc_trace_buffer);
> }
I think you can call free unconditionally.
More information about the Libc-alpha
mailing list