[PATCH] perf tools: Fix a possible memory leak

From: Namhyung Kim
Date: Sun Mar 16 2014 - 21:23:06 EST


Checking default guest machine should be done before allocating event
structures otherwise it'll leak memory.

Cc: Don Zickus <dzickus@xxxxxxxxxx>
Cc: Jiri Olsa <jolsa@xxxxxxxxxx>
Signed-off-by: Namhyung Kim <namhyung@xxxxxxxxxx>
---
tools/perf/util/event.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/tools/perf/util/event.c b/tools/perf/util/event.c
index 3e580be0f6fb..eab930d28159 100644
--- a/tools/perf/util/event.c
+++ b/tools/perf/util/event.c
@@ -445,6 +445,9 @@ int perf_event__synthesize_threads(struct perf_tool *tool,
union perf_event *comm_event, *mmap_event, *fork_event;
int err = -1;

+ if (machine__is_default_guest(machine))
+ return 0;
+
comm_event = malloc(sizeof(comm_event->comm) + machine->id_hdr_size);
if (comm_event == NULL)
goto out;
@@ -457,9 +460,6 @@ int perf_event__synthesize_threads(struct perf_tool *tool,
if (fork_event == NULL)
goto out_free_mmap;

- if (machine__is_default_guest(machine))
- return 0;
-
snprintf(proc_path, sizeof(proc_path), "%s/proc", machine->root_dir);
proc = opendir(proc_path);

--
1.7.11.7

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/