From patchwork Mon Sep 21 16:27:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "gregkh@linuxfoundation.org" X-Patchwork-Id: 263623 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-14.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7E74CC4346A for ; Mon, 21 Sep 2020 16:54:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 527282076E for ; Mon, 21 Sep 2020 16:54:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1600707270; bh=WtErtWdQaKWcND03XTQEdTD2XtMNZkJt/CUV5bC/tRA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=IpHVIhmGhg/PXKZxrZOY00lxpcR/ZFj0NXv+zzL7hQRXYeY/S54aRIOq3yW8Yy7ei bNvHwgworZaO0OOx4VLuKiPEZID/Yn8VQmtXerreyU7lkZ9QZk5iAdGKYbCzeY/a4l mC5mMRxKaOl5MWF7Be6qFkc+xoaisz85cdyqlL5Y= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727899AbgIUQqU (ORCPT ); Mon, 21 Sep 2020 12:46:20 -0400 Received: from mail.kernel.org ([198.145.29.99]:52352 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727431AbgIUQqQ (ORCPT ); Mon, 21 Sep 2020 12:46:16 -0400 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 53BA22223E; Mon, 21 Sep 2020 16:46:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1600706775; bh=WtErtWdQaKWcND03XTQEdTD2XtMNZkJt/CUV5bC/tRA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pmTSuhR5WQ8mIET6yxuqzZC8QxS3PlyhA1jeOcHJ24BIPAy5IlBMR3LUJ8P4qrsCf uQQuJm4M46xbp/ErBE4UZwtP4xM8kaHxp5QbBJLhKWE5EXYtjumeA7J6FleHS+FGKP CqymGrsGTtynocFqqI2giQeib7bgKX0O3stiHWr4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Namhyung Kim , Jiri Olsa , Alexander Shishkin , Andi Kleen , Ian Rogers , John Garry , Kajol Jain , Mark Rutland , Peter Zijlstra , Stephane Eranian , Arnaldo Carvalho de Melo , Sasha Levin Subject: [PATCH 5.8 060/118] perf metric: Fix some memory leaks Date: Mon, 21 Sep 2020 18:27:52 +0200 Message-Id: <20200921162039.141888218@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200921162036.324813383@linuxfoundation.org> References: <20200921162036.324813383@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Namhyung Kim [ Upstream commit 4f57a1ed749a81ec553d89233cab53db9365e193 ] 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: b18f3e365019d ("perf stat: Support JSON metrics in perf stat") Signed-off-by: Namhyung Kim Acked-by: Jiri Olsa Cc: Alexander Shishkin Cc: Andi Kleen Cc: Ian Rogers Cc: John Garry Cc: Kajol Jain Cc: Mark Rutland Cc: Peter Zijlstra Cc: Stephane Eranian Link: http://lore.kernel.org/lkml/20200915031819.386559-2-namhyung@kernel.org Signed-off-by: Arnaldo Carvalho de Melo Signed-off-by: Sasha Levin --- tools/perf/util/metricgroup.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.c index 9e21aa767e417..344a75718afc3 100644 --- a/tools/perf/util/metricgroup.c +++ b/tools/perf/util/metricgroup.c @@ -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); } @@ -726,7 +729,7 @@ 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); @@ -734,11 +737,11 @@ int metricgroup__parse_groups(const struct option *opt, 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; }