diff mbox series

[2/8] trace-cmd record: Prevent a memory leak in show_error()

Message ID 20241029080117.625177-3-jmarchan@redhat.com (mailing list archive)
State Accepted
Commit 6295bcc14322a5e67da3452232e4951452661a82
Headers show
Series trace-cmd: fix misc issues found by static analysis | expand

Commit Message

Jerome Marchand Oct. 29, 2024, 8:01 a.m. UTC
In show_error() the pointer p is used for several functions. At first,
it contain a substring of path.

Then it is replaced by either an allocated string containing the path
to the error log file or the result of read_path(), neither of which
are freed when exiting.

Free p in both case in the exit path.

Fixes a RESOURCE_LEAK error (CWE-772)

Signed-off-by: Jerome Marchand <jmarchan@redhat.com>
---
 tracecmd/trace-record.c | 1 +
 1 file changed, 1 insertion(+)
diff mbox series

Patch

diff --git a/tracecmd/trace-record.c b/tracecmd/trace-record.c
index a008cdfd..3c42cdf0 100644
--- a/tracecmd/trace-record.c
+++ b/tracecmd/trace-record.c
@@ -2374,6 +2374,7 @@  static void show_error(const char *file, const char *type)
 
  out:
 	printf("Failed %s of %s\n", type, file);
+	free(p);
 	free(path);
 	return;
 }