[PATCH] malloc: fix memleak in function muntrace

chenzefeng chenzefeng2@huawei.com
Sun Apr 19 07:37:54 GMT 2020


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(+)

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);
 }
-- 
2.12.3



More information about the Libc-alpha mailing list