Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp2354183pxb; Mon, 20 Sep 2021 19:53:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzEE/L8wTD8cWx2tIAMqb544jQ8biDwmbOg4TjxqEgPgi2n9rsdICKTRnUKga40CgYTqIkB X-Received: by 2002:a02:6646:: with SMTP id l6mr22113457jaf.51.1632192799682; Mon, 20 Sep 2021 19:53:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632192799; cv=none; d=google.com; s=arc-20160816; b=CCu8kHB+RMGUJBegXM0zPe+AmpDbq3oJd6HX7AT/GZjc3WTgRj3JISZLD8IZ+9QtSN MkkcsschyeVkSL3+CdX7zc2w2vYAlPEMjP5Hglcxgz0B6sPuv3YIK8mKfTzaXOT8x4u4 XnmOi8HDFULGuhJOX96Gl3naGi5s8Ipa8DNoKLM7eOToxvH6FJ7o8nrlOPdbWSk87s10 JTXg0D1/owdt6tvpkt7yxEKB0TFyVOXLYpgzspNBe2xI5ay8rn15313zaM1HkrXV0CYi Mxq1MbRL1pa0KF6SnNlMzg/r+orMZBOsgzcNe73wNYrWyiiJgAuDIZerngiDzHfDfkn/ 95nA== 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=BtliFKJB15QVphcu5wy9WyyhvYAZMHYGEWFQGRi9tTg=; b=p89xn+/aYeCJY7/9ape8T1Ysf2RIcVu4mjrV9tIInOmPCmdhDhigTWzNJkYBU3i4JS uboNgscvfrMOmfmOmuKgcHzI765vgMK+y1wFMjccOIoWg6V2rVt9430+EKJCkiihv7Tu GY+W8KqjITBS9L6422RO/Xj1tvVha31E1rLKaTXO+muWgU6iMfmhE23HEtlkHu6Judfr l59MrfIE+2lvzIQywmxFFJcBLNQUspKP3jO2mgYPrGolbXxchC0UjSUKMcNR149T4iLK C2mZv2RETNLSQdtcyHtmwmNnZYz9ATkrw14Sxy4YS2qAcEkwz0KZPZqAANLaE4LC6DEV zcZg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="0Lpt/KZk"; 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=pass (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 t11si10960544ilu.179.2021.09.20.19.53.08; Mon, 20 Sep 2021 19:53:19 -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=@linuxfoundation.org header.s=korg header.b="0Lpt/KZk"; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349461AbhITS5T (ORCPT + 99 others); Mon, 20 Sep 2021 14:57:19 -0400 Received: from mail.kernel.org ([198.145.29.99]:33188 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1384542AbhITSsT (ORCPT ); Mon, 20 Sep 2021 14:48:19 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 0849F6336E; Mon, 20 Sep 2021 17:33:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1632159237; bh=x7rPBipq78G9aI//ptbkYNECguRYHYeDLrRDC8NK408=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=0Lpt/KZk6Vp37y3oYNB2revlVP08cPpfOHxgsQ8A2Vu179mu5TVZ/PM4Jz0hU1U2L ePPUysgw/s3yMPSr/wMn6G9382iow86sQbW/YD5BUKEm987mBQLXNCi42Xy++RFKc5 FAD/Gji0stlBzg50OHp0PupACVDUI9T3TksrYeGE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Riccardo Mancini , Alexander Shishkin , Ian Rogers , Jin Yao , Jiri Olsa , Mark Rutland , Namhyung Kim , Peter Zijlstra , Song Liu , Arnaldo Carvalho de Melo , Sasha Levin Subject: [PATCH 5.14 140/168] perf config: Fix caching and memory leak in perf_home_perfconfig() Date: Mon, 20 Sep 2021 18:44:38 +0200 Message-Id: <20210920163926.257664516@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210920163921.633181900@linuxfoundation.org> References: <20210920163921.633181900@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: Arnaldo Carvalho de Melo [ Upstream commit 261f491133aecb943ccfdc3b3794e2d775607a87 ] Acaict, perf_home_perfconfig() is supposed to cache the result of home_perfconfig, which returns the default location of perfconfig for the user, given the HOME environment variable. However, the current implementation calls home_perfconfig every time perf_home_perfconfig() is called (so no caching is actually performed), replacing the previous pointer, thus also causing a memory leak. This patch adds a check of whether either config or failed is set and, in that case, directly returns config without calling home_perfconfig at each invocation. Fixes: f5f03e19ce14fc31 ("perf config: Add perf_home_perfconfig function") Signed-off-by: Riccardo Mancini Cc: Alexander Shishkin Cc: Ian Rogers Cc: Jin Yao Cc: Jiri Olsa Cc: Mark Rutland Cc: Namhyung Kim Cc: Peter Zijlstra Cc: Song Liu Link: http://lore.kernel.org/lkml/20210820130817.740536-1-rickyman7@gmail.com [ Removed needless double check for the 'failed' variable ] Signed-off-by: Arnaldo Carvalho de Melo Signed-off-by: Sasha Levin --- tools/perf/util/config.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tools/perf/util/config.c b/tools/perf/util/config.c index 63d472b336de..4fb5e90d7a57 100644 --- a/tools/perf/util/config.c +++ b/tools/perf/util/config.c @@ -581,7 +581,10 @@ const char *perf_home_perfconfig(void) static const char *config; static bool failed; - config = failed ? NULL : home_perfconfig(); + if (failed || config) + return config; + + config = home_perfconfig(); if (!config) failed = true; -- 2.30.2