From mboxrd@z Thu Jan 1 00:00:00 1970 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=-20.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, 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 3E465C433F5 for ; Mon, 20 Sep 2021 18:55:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2464560F6B for ; Mon, 20 Sep 2021 18:55:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344299AbhITS5U (ORCPT ); Mon, 20 Sep 2021 14:57:20 -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