From: Ian Rogers <irog...@google.com>

[ Upstream commit a159e2fe89b4d1f9fb54b0ae418b961e239bf617 ]

Avoid a simple memory leak.

Signed-off-by: Ian Rogers <irog...@google.com>
Cc: Alexander Shishkin <alexander.shish...@linux.intel.com>
Cc: Alexei Starovoitov <a...@kernel.org>
Cc: Andi Kleen <a...@linux.intel.com>
Cc: Andrii Nakryiko <andr...@fb.com>
Cc: Cong Wang <xiyou.wangc...@gmail.com>
Cc: Daniel Borkmann <dan...@iogearbox.net>
Cc: Jin Yao <yao....@linux.intel.com>
Cc: Jiri Olsa <jo...@redhat.com>
Cc: John Fastabend <john.fastab...@gmail.com>
Cc: John Garry <john.ga...@huawei.com>
Cc: Kajol Jain <kj...@linux.ibm.com>
Cc: Kan Liang <kan.li...@linux.intel.com>
Cc: Kim Phillips <kim.phill...@amd.com>
Cc: Mark Rutland <mark.rutl...@arm.com>
Cc: Martin KaFai Lau <ka...@fb.com>
Cc: Namhyung Kim <namhy...@kernel.org>
Cc: Peter Zijlstra <pet...@infradead.org>
Cc: Song Liu <songliubrav...@fb.com>
Cc: Stephane Eranian <eran...@google.com>
Cc: Vince Weaver <vincent.wea...@maine.edu>
Cc: Yonghong Song <y...@fb.com>
Cc: b...@vger.kernel.org
Cc: kp singh <kpsi...@chromium.org>
Cc: net...@vger.kernel.org
Link: http://lore.kernel.org/lkml/20200508053629.210324-10-irog...@google.com
Signed-off-by: Arnaldo Carvalho de Melo <a...@redhat.com>
Signed-off-by: Sasha Levin <sas...@kernel.org>
---
 tools/perf/util/metricgroup.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.c
index 940a6e7a68549..7753c3091478a 100644
--- a/tools/perf/util/metricgroup.c
+++ b/tools/perf/util/metricgroup.c
@@ -174,6 +174,7 @@ static int metricgroup__setup_events(struct list_head 
*groups,
                if (!evsel) {
                        pr_debug("Cannot resolve %s: %s\n",
                                        eg->metric_name, eg->metric_expr);
+                       free(metric_events);
                        continue;
                }
                for (i = 0; i < eg->idnum; i++)
@@ -181,11 +182,13 @@ static int metricgroup__setup_events(struct list_head 
*groups,
                me = metricgroup__lookup(metric_events_list, evsel, true);
                if (!me) {
                        ret = -ENOMEM;
+                       free(metric_events);
                        break;
                }
                expr = malloc(sizeof(struct metric_expr));
                if (!expr) {
                        ret = -ENOMEM;
+                       free(metric_events);
                        break;
                }
                expr->metric_expr = eg->metric_expr;
-- 
2.25.1



Reply via email to