Skip to content

Commit 4f57a1e

Browse files
namhyungacmel
authored andcommitted
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: b18f3e3 ("perf stat: Support JSON metrics in perf stat") Signed-off-by: Namhyung Kim <[email protected]> Acked-by: Jiri Olsa <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: Andi Kleen <[email protected]> Cc: Ian Rogers <[email protected]> Cc: John Garry <[email protected]> Cc: Kajol Jain <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Stephane Eranian <[email protected]> Link: http://lore.kernel.org/lkml/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent 22fe5a2 commit 4f57a1e

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

tools/perf/util/metricgroup.c

+5-2
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,9 @@ void metricgroup__print(bool metrics, bool metricgroups, char *filter,
530530
continue;
531531
strlist__add(me->metrics, s);
532532
}
533+
534+
if (!raw)
535+
free(s);
533536
}
534537
free(omg);
535538
}
@@ -1040,19 +1043,19 @@ static int parse_groups(struct evlist *perf_evlist, const char *str,
10401043
ret = metricgroup__add_metric_list(str, metric_no_group,
10411044
&extra_events, &metric_list, map);
10421045
if (ret)
1043-
return ret;
1046+
goto out;
10441047
pr_debug("adding %s\n", extra_events.buf);
10451048
bzero(&parse_error, sizeof(parse_error));
10461049
ret = __parse_events(perf_evlist, extra_events.buf, &parse_error, fake_pmu);
10471050
if (ret) {
10481051
parse_events_print_error(&parse_error, extra_events.buf);
10491052
goto out;
10501053
}
1051-
strbuf_release(&extra_events);
10521054
ret = metricgroup__setup_events(&metric_list, metric_no_merge,
10531055
perf_evlist, metric_events);
10541056
out:
10551057
metricgroup__free_metrics(&metric_list);
1058+
strbuf_release(&extra_events);
10561059
return ret;
10571060
}
10581061

0 commit comments

Comments
 (0)