diff mbox series

[v3] malloc: fix memleak in function muntrace

Message ID 20200421114800.26450-1-chenzefeng2@huawei.com
State New
Headers show
Series [v3] malloc: fix memleak in function muntrace | expand

Commit Message

chenzefeng April 21, 2020, 11:48 a.m. UTC
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>
---
 malloc/mtrace.c | 2 ++
 1 file changed, 2 insertions(+)

Comments

Florian Weimer April 22, 2020, 12:39 p.m. UTC | #1
* 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>

Same question as before:

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..5d7bc62857 100644
> --- a/malloc/mtrace.c
> +++ b/malloc/mtrace.c
> @@ -365,4 +365,6 @@ muntrace (void)
>  
>    fprintf (f, "= End\n");
>    fclose (f);
> +  free (malloc_trace_buffer);
> +  malloc_trace_buffer == NULL;
>  }

Please test your patches before you post them:

mtrace.c: In function ‘muntrace’:
mtrace.c:369:23: error: statement with no effect [-Werror=unused-value]
   malloc_trace_buffer == NULL;
                       ^
chenzefeng April 24, 2020, 1:24 a.m. UTC | #2
* Florian Weimer:


>* 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>

>Same question as before:

>glibc uses copyright assignment to the FSF for contributions, and not the DCO.

>I trust this contribution is covered by Huawei's copyright assignment?

Yet, this patch uses copyright assignment to the FSF for contributions.

>> ---
>>  malloc/mtrace.c | 2 ++
>>  1 file changed, 2 insertions(+)
>>
>> diff --git a/malloc/mtrace.c b/malloc/mtrace.c index 
>> 7e7719df97..5d7bc62857 100644
>> --- a/malloc/mtrace.c
>> +++ b/malloc/mtrace.c
>> @@ -365,4 +365,6 @@ muntrace (void)
>>  
>>    fprintf (f, "= End\n");
>>    fclose (f);
>>+  free (malloc_trace_buffer);
>> +  malloc_trace_buffer == NULL;
>>  }

>Please test your patches before you post them:

>mtrace.c: In function ‘muntrace’:
>mtrace.c:369:23: error: statement with no effect [-Werror=unused-value]
>   malloc_trace_buffer == NULL;
Fix it in patch v4

                       ^
diff mbox series

Patch

diff --git a/malloc/mtrace.c b/malloc/mtrace.c
index 7e7719df97..5d7bc62857 100644
--- a/malloc/mtrace.c
+++ b/malloc/mtrace.c
@@ -365,4 +365,6 @@  muntrace (void)
 
   fprintf (f, "= End\n");
   fclose (f);
+  free (malloc_trace_buffer);
+  malloc_trace_buffer == NULL;
 }