diff mbox series

[19/38] trace-cmd record: prevent memory leak in add_all_instances()

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

Commit Message

Jerome Marchand June 5, 2024, 1:40 p.m. UTC
In __add_all_instances(), name is allocated by strdup(dent->d_name)
but is never freed. Anyway, the content of *name is copied in
append_file() and allocate_instance(), so it didn't need to be
strduped to begin with.

Fixes a RESOURCE_LEAK error (CWE-772)

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

Patch

diff --git a/tracecmd/trace-record.c b/tracecmd/trace-record.c
index c4d43469..a9e5e64d 100644
--- a/tracecmd/trace-record.c
+++ b/tracecmd/trace-record.c
@@ -422,7 +422,7 @@  static int __add_all_instances(const char *tracing_dir)
 	}
 
 	while ((dent = readdir(dir))) {
-		const char *name = strdup(dent->d_name);
+		const char *name = dent->d_name;
 		char *instance_path;
 		struct buffer_instance *instance;