Thread (3 messages) 3 messages, 2 authors, 2012-09-05
STALE5135d

[PATCH] perf tool: fix trivial memory leak while calling system_path()

From: liang xie <hidden>
Date: 2012-09-05 13:48:56
Also in: lkml
Subsystem: performance events subsystem, the rest · Maintainers: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo, Namhyung Kim, Linus Torvalds

A trivial memory leak fix while calling system_path

Signed-off-by: Liang Xie <redacted>
---
 tools/perf/util/exec_cmd.c |    6 ++++--
 tools/perf/util/help.c     |    1 +
 2 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/tools/perf/util/exec_cmd.c b/tools/perf/util/exec_cmd.c
index 7adf4ad..790cc95 100644
--- a/tools/perf/util/exec_cmd.c
+++ b/tools/perf/util/exec_cmd.c
@@ -83,8 +83,8 @@ void setup_path(void)
 {
 	const char *old_path = getenv("PATH");
 	struct strbuf new_path = STRBUF_INIT;
-
-	add_path(&new_path, perf_exec_path());
+	const char *exec_path = perf_exec_path();
+	add_path(&new_path, exec_path);
 	add_path(&new_path, argv0_path);

 	if (old_path)
@@ -95,6 +95,8 @@ void setup_path(void)
 	setenv("PATH", new_path.buf, 1);

 	strbuf_release(&new_path);
+	if (exec_path)
+		free((void *)exec_path);
 }

 static const char **prepare_perf_cmd(const char **argv)
diff --git a/tools/perf/util/help.c b/tools/perf/util/help.c
index 6f2975a..798f66d 100644
--- a/tools/perf/util/help.c
+++ b/tools/perf/util/help.c
@@ -187,6 +187,7 @@ void load_command_list(const char *prefix,
 		uniq(other_cmds);
 	}
 	exclude_cmds(other_cmds, main_cmds);
+	free((void *)exec_path);
 }

 void list_commands(const char *title, struct cmdnames *main_cmds,
-- 
1.7.1
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help