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

"Jerome Marchand" <[email protected]>
Newsgroups org.kernel.vger.linux-trace-devel
Message-ID <[email protected]>
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 <[email protected]>
---
 tracecmd/trace-record.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

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;
 
-- 
2.44.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.