[PATCH 13/41] perf machine: Free root_dir in machine__init() error path

From: Arnaldo Carvalho de Melo
Date: Fri Feb 16 2018 - 14:38:24 EST


From: Jiri Olsa <jolsa@xxxxxxxxxx>

Free root_dir in machine__init() error path.

Signed-off-by: Jiri Olsa <jolsa@xxxxxxxxxx>
Cc: Alexander Shishkin <alexander.shishkin@xxxxxxxxxxxxxxx>
Cc: David Ahern <dsahern@xxxxxxxxx>
Cc: Namhyung Kim <namhyung@xxxxxxxxxx>
Cc: Peter Zijlstra <peterz@xxxxxxxxxxxxx>
Link: http://lkml.kernel.org/r/20180215122635.24029-4-jolsa@xxxxxxxxxx
Signed-off-by: Arnaldo Carvalho de Melo <acme@xxxxxxxxxx>
---
tools/perf/util/machine.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c
index b05a67464c03..c976384f9022 100644
--- a/tools/perf/util/machine.c
+++ b/tools/perf/util/machine.c
@@ -50,6 +50,8 @@ static void machine__threads_init(struct machine *machine)

int machine__init(struct machine *machine, const char *root_dir, pid_t pid)
{
+ int err = -ENOMEM;
+
memset(machine, 0, sizeof(*machine));
map_groups__init(&machine->kmaps, machine);
RB_CLEAR_NODE(&machine->rb_node);
@@ -79,7 +81,7 @@ int machine__init(struct machine *machine, const char *root_dir, pid_t pid)
char comm[64];

if (thread == NULL)
- return -ENOMEM;
+ goto out;

snprintf(comm, sizeof(comm), "[guest/%d]", pid);
thread__set_comm(thread, comm, 0);
@@ -87,7 +89,11 @@ int machine__init(struct machine *machine, const char *root_dir, pid_t pid)
}

machine->current_tid = NULL;
+ err = 0;

+out:
+ if (err)
+ zfree(&machine->root_dir);
return 0;
}

--
2.14.3