Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp3296166pxk; Mon, 21 Sep 2020 09:57:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwAwfEF01K7YgTbj78yNoR0v5r8rsi0nOOzL6Ufd/9P/M6toN8sRO3ix0ajxo3ivQWMiw/E X-Received: by 2002:a17:906:a947:: with SMTP id hh7mr396331ejb.126.1600707468715; Mon, 21 Sep 2020 09:57:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600707468; cv=none; d=google.com; s=arc-20160816; b=ZK+/SxmzAD+4/WZ6mqfOtZnYlI6N1dLM/aYBUzSv3NmMw+BtUg8ggId1U+jI0xTzI+ bbAEL/EhwyC73i32VWMUMQx8mj329ukvWiapnOgbulWZVEnuiDBfrl50vwyCylRuLDkm jLkczdp7vMk5NncAoJOlxJelDl86z+Q/2fS5vwOewr0QTdrJZj3i6o814cbOmirq/3nt oDN7rnCF7qEouwLSnPzoJeh6RIW4tb25lPoZzNkCQsTaMqevLTqoxYxVtkexErxBtIlE J7tmgt3G6sLC2yNAyym9GZkpGb+tR/RzhLOLS0eVUmy3CTGzA2vr/vEhqvrVP4iliHu5 TwaQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=WyPFZYy/967bJYLSCL2hYA+dqGdb8jh19Bb9LhvjlnE=; b=mUc0PK9IYVk+G8ljaX/NeYmaKWXfIEO96PYZAEn6dG7pCtiOVYykA9HIZOHWee4wp/ /tDar0wvoafwkR/uoQZVpZiL17uPu5QruVc8RHVlKxc9RGj96QNLzsg3jsTz6fc3NxIU pvZCcB0h79QgaHZxn5ugGv0XiJ+woc4HGkbUHa02/FEfVDJpZ8NE7UCA5Gk8u5I5sQ+T ZSQzhTrXhU3rBzA0lFSEVASM+6zDnjLJcgydcmb72DtE47IAurKCZNjB157PhUS6dZYy /oX9Cg7qelQai0K2wbwqzjxSrQbNHfHGmb9lCuMsgJyE0THUKMMqEMybq5Wi3tl7+PUl jiHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=pmTSuhR5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r22si8357462eji.521.2020.09.21.09.57.24; Mon, 21 Sep 2020 09:57:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=pmTSuhR5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728145AbgIUQqU (ORCPT + 99 others); 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 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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; } -- 2.25.1