From a68088ef3160d75f02bb6af5f552ca507e51df56 Mon Sep 17 00:00:00 2001 From: Junnan Xu Date: Fri, 17 Jun 2022 15:20:04 +0800 Subject: [PATCH] utrace: fix memory leak Fixes following memory leak: 14 bytes in 1 blocks are definitely lost in loss record 1 of 5 at 0x4079514: malloc (vg_replace_malloc.c:309) by 0x4049A04: vasprintf (vasprintf.c:13) by 0x4046354: asprintf (asprintf.c:10) by 0x80491A9: main (in /root/utrace) 134 bytes in 1 blocks are definitely lost in loss record 3 of 5 at 0x4079514: malloc (vg_replace_malloc.c:309) by 0x4049A04: vasprintf (vasprintf.c:13) by 0x4046354: asprintf (asprintf.c:10) by 0x8049208: main (in /root/utrace) Signed-off-by: Junnan Xu Reviewed-by: Rui Salvaterra --- trace/trace.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/trace/trace.c b/trace/trace.c index d895798..6fd321f 100644 --- a/trace/trace.c +++ b/trace/trace.c @@ -381,6 +381,10 @@ int main(int argc, char **argv, char **envp) ULOG_ERR("failed to exec %s: %m\n", _argv[0]); free(_argv); + if (_envp[0]) + free(_envp[0]); + if (newenv == 2 && _envp[1]) + free(_envp[1]); free(_envp); return ret; } -- 2.30.2