[PATCH v2] utrace: fix memory leak

junnanx.xu at gmail.com junnanx.xu at gmail.com
Fri Jun 17 00:20:04 PDT 2022


From: Junnan Xu <junnanx.xu at gmail.com>

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 <junnanx.xu at gmail.com>
---
 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.21.0.windows.1




More information about the openwrt-devel mailing list