Commit 4f57a1ed authored by Namhyung Kim's avatar Namhyung Kim Committed by Arnaldo Carvalho de Melo

perf metric: Fix some memory leaks

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: b18f3e36 ("perf stat: Support JSON metrics in perf stat")
Signed-off-by: default avatarNamhyung Kim <namhyung@kernel.org>
Acked-by: default avatarJiri 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.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 22fe5a25
...@@ -530,6 +530,9 @@ void metricgroup__print(bool metrics, bool metricgroups, char *filter, ...@@ -530,6 +530,9 @@ void metricgroup__print(bool metrics, bool metricgroups, char *filter,
continue; continue;
strlist__add(me->metrics, s); strlist__add(me->metrics, s);
} }
if (!raw)
free(s);
} }
free(omg); free(omg);
} }
...@@ -1040,7 +1043,7 @@ static int parse_groups(struct evlist *perf_evlist, const char *str, ...@@ -1040,7 +1043,7 @@ static int parse_groups(struct evlist *perf_evlist, const char *str,
ret = metricgroup__add_metric_list(str, metric_no_group, ret = metricgroup__add_metric_list(str, metric_no_group,
&extra_events, &metric_list, map); &extra_events, &metric_list, map);
if (ret) if (ret)
return ret; goto out;
pr_debug("adding %s\n", extra_events.buf); pr_debug("adding %s\n", extra_events.buf);
bzero(&parse_error, sizeof(parse_error)); bzero(&parse_error, sizeof(parse_error));
ret = __parse_events(perf_evlist, extra_events.buf, &parse_error, fake_pmu); ret = __parse_events(perf_evlist, extra_events.buf, &parse_error, fake_pmu);
...@@ -1048,11 +1051,11 @@ static int parse_groups(struct evlist *perf_evlist, const char *str, ...@@ -1048,11 +1051,11 @@ static int parse_groups(struct evlist *perf_evlist, const char *str,
parse_events_print_error(&parse_error, extra_events.buf); parse_events_print_error(&parse_error, extra_events.buf);
goto out; goto out;
} }
strbuf_release(&extra_events);
ret = metricgroup__setup_events(&metric_list, metric_no_merge, ret = metricgroup__setup_events(&metric_list, metric_no_merge,
perf_evlist, metric_events); perf_evlist, metric_events);
out: out:
metricgroup__free_metrics(&metric_list); metricgroup__free_metrics(&metric_list);
strbuf_release(&extra_events);
return ret; return ret;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment