Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp1463416pxb; Fri, 20 Aug 2021 06:13:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzyHPBfP1V3Dq5ww+dlgA1BYT4jLsETckLz+ks2mHAFEnKucdprDrfxLlhpjG56Vv+HGwTj X-Received: by 2002:a5e:c905:: with SMTP id z5mr15992412iol.33.1629465194231; Fri, 20 Aug 2021 06:13:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629465194; cv=none; d=google.com; s=arc-20160816; b=ONZS8wmHZx0NUkRKB3p3sQDTcEiIjqKfbM5iRFvdKwzlOW+XBbyduTKZcxD3im3ID/ t2n4APXu3aqe4TSTqFA1iqxmynP1CxnYL4S1dEf0woP4UUyUMlOrbZRNX17Ocv2/Ovgr 0nNtsR+EkqbBfthu89UXEEnC4KH8lGFYw7VBL4SX5ruh132I/SPJUhgKwqMtbhBli/fJ eB/JDfERWqc/13U43EIemuRhzax7cBEX5Z2I6U6wdaA+5tSOi1iqrwVjmUOgJ6lw2rW9 nZKS1yGV78fvmEHr1ArzJ98XXD3vJ6ld2aVp13U+qGU9amVSitZPw5LsSngvzqHxKC8X CBzA== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=amLfY2WyHMkOd7qaXpy+DB72ahvQ2PinE48ltai+NY8=; b=CeaAhO2TCZ6eRZ0e3lPKdRgufASyGoymQb7Te6gu144COzA9qVu9+DXEkevEpSH5W+ W320K/1n59/lQCpvirUYYDfEYi0mRQMJSX28p4z4BRbxTunRuf47JoatoUzr+EKXk+Gm W2NnOEySuSFy3a3soOzUF2wHLB7sMPkELwg7omZmwFgiH03xRe5ngxVIfsJrVdIbOmvj ZXcAisNLS8OIm/wH14vJKfGooRbOwGLXxnTo63girMmv3Fm43shDfzwLzKNc+dAdeAPu 0Pq/+/zXcuVlGdEs6+HlrsFx2O3lxjudb+E3r8cZkHxoFTqOuanefDb5Bkwy+lNog+4f SnxA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=rwSw1HOF; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d12si7055821ilg.105.2021.08.20.06.13.02; Fri, 20 Aug 2021 06:13:14 -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=@gmail.com header.s=20161025 header.b=rwSw1HOF; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240613AbhHTNKd (ORCPT + 99 others); Fri, 20 Aug 2021 09:10:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44620 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238510AbhHTNKd (ORCPT ); Fri, 20 Aug 2021 09:10:33 -0400 Received: from mail-ej1-x636.google.com (mail-ej1-x636.google.com [IPv6:2a00:1450:4864:20::636]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 30389C061575; Fri, 20 Aug 2021 06:09:55 -0700 (PDT) Received: by mail-ej1-x636.google.com with SMTP id h9so20184688ejs.4; Fri, 20 Aug 2021 06:09:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=amLfY2WyHMkOd7qaXpy+DB72ahvQ2PinE48ltai+NY8=; b=rwSw1HOFFZvRjHgzdxD6wIWXmbfC1tIbpjup1mvWgKiVHgnG/r3AedF9t81fLmqkHf 7E+PAgpDncoeBFUw0R77F9l28gYw3HhpT+ljs2Bh8Z/YJRBKD98iDfhnNH8s8QSRXalX sDTXk82uptoHbmO990kyKWxdC3pjMrpD8GLdVICdK3hdyuhBwFbpoMkqI93V/Ks50YF6 L7ea3Olo1ttG6U2z8BK7eIWxEE0fDmuMYF+b3rTDshcilGXzyMp99bern34TouDOIRXI qdhZ8EjFLv31xAJJaz0rHXZyo2N7gtkS9QaUmtj4UPDle/VtHgpRP8SVJTlZa545zR1/ C2zw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=amLfY2WyHMkOd7qaXpy+DB72ahvQ2PinE48ltai+NY8=; b=l0eFYTs7Ha6zwD/5NYAS3VqJTGEc/MW+lTwibWMyeNy7JUu8YTiSGDwjXgrpkg/3DS gZ6gLWrBCXTw8hUujQsLXgJmhe8S4EdfoIOYVsJRPUNzl83EWSP+vNilayK2kunJWQi9 G41APKscb5Os7MyaSV9uUSBEmKQVkLWgjVWmCpEEIov4X0oxxlyhMSyNYVg7y8WQYO7T xyVWJYoO9hGudsTn0UrvkvH/9G7UVmwPwkBGYp8d3oj/2StYDMq2xBpo55lNfdLDcC+K C1bKlLuvBc6M+Zx1WYsYB/810/i2YCC9vJRz9SznVL6PIRFFjirUVS2MqXOj7WgQTMYf nHUw== X-Gm-Message-State: AOAM533rEfg5ScZusVjT+7rmehl9f0nZwLTaWT5Gre3AASQuEwc7qOxY MNS5ML/kjbeCjjlokImTTF4= X-Received: by 2002:a17:906:7154:: with SMTP id z20mr1255396ejj.547.1629464993668; Fri, 20 Aug 2021 06:09:53 -0700 (PDT) Received: from honeypot.. (mob-176-243-242-182.net.vodafone.it. [176.243.242.182]) by smtp.googlemail.com with ESMTPSA id n2sm3594518edi.32.2021.08.20.06.09.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Aug 2021 06:09:53 -0700 (PDT) From: Riccardo Mancini To: Arnaldo Carvalho de Melo Cc: Ian Rogers , Namhyung Kim , Riccardo Mancini , Jiri Olsa , Peter Zijlstra , Ingo Molnar , Mark Rutland , Alexander Shishkin , Jiri Olsa , Jin Yao , Song Liu , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] perf config: fix caching and memory leak in perf_home_perfconfig Date: Fri, 20 Aug 2021 15:08:17 +0200 Message-Id: <20210820130817.740536-1-rickyman7@gmail.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. Cc: Jiri Olsa Fixes: f5f03e19ce14fc31 ("perf config: Add perf_home_perfconfig function") Signed-off-by: Riccardo Mancini --- tools/perf/util/config.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tools/perf/util/config.c b/tools/perf/util/config.c index 63d472b336de21d4..6ab670cdf512507e 100644 --- a/tools/perf/util/config.c +++ b/tools/perf/util/config.c @@ -581,6 +581,9 @@ const char *perf_home_perfconfig(void) static const char *config; static bool failed; + if (config || failed) + return config; + config = failed ? NULL : home_perfconfig(); if (!config) failed = true; -- 2.31.1