diff mbox series

malloc: fix memleak in function muntrace

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

Commit Message

chenzefeng April 19, 2020, 7:37 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 19, 2020, 11:39 a.m. UTC | #1
* chenzefeng:

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

I don't think this will build.  The global variable is called
malloc_trace_buffer.
chenzefeng April 20, 2020, 1:49 p.m. UTC | #2
* Florian Weimer:

>* chenzefeng:

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

>I don't think this will build.  The global variable is called malloc_trace_buffer.

I am sorry, I had not got the correctly patch from local file. I commit it again, thanks for you review.
diff mbox series

Patch

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