Skip to content

Commit

Permalink
perf metric: Fix some memory leaks
Browse files Browse the repository at this point in the history
BugLink: https://bugs.launchpad.net/bugs/1896795

[ Upstream commit 4f57a1e ]

I found some memory leaks while reading the metric code.  Some are real
and others only occur in the error path.  When it failed during metric
or event parsing, it should release all resources properly.

Fixes: b18f3e3 ("perf stat: Support JSON metrics in perf stat")
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Acked-by: Jiri Olsa <jolsa@redhat.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lore.kernel.org/lkml/20200915031819.386559-2-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Paolo Pisati <paolo.pisati@canonical.com>
  • Loading branch information
namhyung authored and piso77 committed Sep 23, 2020
1 parent 4a06bee commit f41eb7e
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions tools/perf/util/metricgroup.c
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,9 @@ void metricgroup__print(bool metrics, bool metricgroups, char *filter,
continue;
strlist__add(me->metrics, s);
}

if (!raw)
free(s);
}
free(omg);
}
Expand Down Expand Up @@ -726,19 +729,19 @@ int metricgroup__parse_groups(const struct option *opt,
ret = metricgroup__add_metric_list(str, metric_no_group,
&extra_events, &group_list);
if (ret)
return ret;
goto out;
pr_debug("adding %s\n", extra_events.buf);
bzero(&parse_error, sizeof(parse_error));
ret = parse_events(perf_evlist, extra_events.buf, &parse_error);
if (ret) {
parse_events_print_error(&parse_error, extra_events.buf);
goto out;
}
strbuf_release(&extra_events);
ret = metricgroup__setup_events(&group_list, metric_no_merge,
perf_evlist, metric_events);
out:
metricgroup__free_egroups(&group_list);
strbuf_release(&extra_events);
return ret;
}

Expand Down

0 comments on commit f41eb7e

Please sign in to comment.