diff mbox series

[v4] malloc: fix memleak in function muntrace

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

Commit Message

chenzefeng April 24, 2020, 1:24 a.m. UTC
when we call functons as follow:
	setenv("MALLOC_TRACE", "/tmp/mtrace.log", 0);
	mtrace();
	...
	muntrace();
It would cause memleak, for the mtrace malloc some memory:
	mtd = malloc(TRACE_BUFFER_SIZE);
and it would not be free. Therefore it should be freed in muntrace.

Signed-off-by: chenzefeng <chenzefeng2@huawei.com>
---
 malloc/mtrace.c | 2 ++
 1 file changed, 2 insertions(+)
diff mbox series

Patch

diff --git a/malloc/mtrace.c b/malloc/mtrace.c
index 7e7719df97..61f4ca3520 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;
 }