Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp1747840pxb; Fri, 20 Aug 2021 13:01:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzledOqRJ8w3shf4Kx2PhNtjdlEu7SqSMymMubophna4oOlkRaocsH+jqRQLP9xPWn/c14T X-Received: by 2002:a5e:d91a:: with SMTP id n26mr16707449iop.96.1629489684259; Fri, 20 Aug 2021 13:01:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629489684; cv=none; d=google.com; s=arc-20160816; b=DQYp3j8RwVxemmllozcM7JL8IXtjmQ+Og0Z7ZF9rSwL7AFaeNnvVq09xBWu3Yos+dO 9Ki30obbw1nWBctXsqGoVeDurogQjDbc4XtBK1y/4ldmyXSSN3vofFy3GDs6oOTM5+Pg lJ6DQNEc4qZyBkhVPkPeb6d8htDedvgmjwOCGvlN19OFJeFz2oCwa+uLuFAywqx/+Z+L 6ytBS5bZLH9yxE9ASZExcTcDqTOmDhxtM5wB0fymhTeBhMo74JkCgl/yyoKucSRz2WGn 0lns3XWBxhilAM1TGEbvSgzpXzxSti3spU5/mdcvdWtW8HwglSLx6kg7Z+HAl2ksY6d5 d60Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:user-agent:date :mime-version:references:in-reply-to:cc:to:from:subject:message-id :dkim-signature; bh=LrJQ81OQnCEJDCTRI1bdIMkvIXdbOY4niFVqWVBoYbo=; b=d7l+CJqE05gISXEGPrBqh02Sb8gizdjn7mQTtlWuQdwSBq7/WXvp04ulcu+fXjP8lB sA/oAxAPNCVo3cHKfYEYXt4GROsifO/oD+HMSck3zGMbIyIU/Lw52oPxkSLZvN6bTO4h xLPMvOUlbaTkWbP3ojb8nmWgjjSTHoZ+aqJsRgn161H3KfoP1aVV6/zxuLm7R4da4fR6 LM8VuzS1IBnmMPAWmdU8SCxT8lncv5B/H8B/QG97VH10uCf4ogpFzjMmWcimq9eGa934 I/gF+OjalHvOW20EhHSKpWOjiFmvCQJ7pKJBCxvZfMceQI1m1ZYDf14XsHq+raaIT+2w KhxQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=MUMI6qye; 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 j10si7866051jat.46.2021.08.20.13.00.52; Fri, 20 Aug 2021 13:01:24 -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=MUMI6qye; 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 S238834AbhHTT7D (ORCPT + 99 others); Fri, 20 Aug 2021 15:59:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55322 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237272AbhHTT7C (ORCPT ); Fri, 20 Aug 2021 15:59:02 -0400 Received: from mail-ej1-x62e.google.com (mail-ej1-x62e.google.com [IPv6:2a00:1450:4864:20::62e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 842BFC06175F; Fri, 20 Aug 2021 12:58:24 -0700 (PDT) Received: by mail-ej1-x62e.google.com with SMTP id h9so22383473ejs.4; Fri, 20 Aug 2021 12:58:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:subject:from:to:cc:in-reply-to:references:mime-version :date:user-agent:content-transfer-encoding; bh=LrJQ81OQnCEJDCTRI1bdIMkvIXdbOY4niFVqWVBoYbo=; b=MUMI6qyeGYIeEf+vPjCyTXp/VW/6UynfEIOdt0MnMQjpJTqVaYMEBnZ3YPks5RX6mY 8OcI4mHibQojokiyTPpc8TTy/ER+r7jo/g49ZI5F9fbQjkYKC72jiaSHCSKj0kAx5Giz +J+wbv2eP/H+CFXmXTu3sHDRrk5VM9A9Jrfk4UNQUPZlaVYVVMpfm9Zjvti449+BrWqf HYmgK7juju2FnIJns8hOk2JsZyzc2yssbetWpB9iY1EvTOrDssqWyOQNO0ryLe3rSCEW CbeQ1cpZ/O+L+XF505yHtD997Hs2Bt6vwSChUSM5nlp7Xv0ZFtrj0QTv9ysuyPV5VvXG RTAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:subject:from:to:cc:in-reply-to :references:mime-version:date:user-agent:content-transfer-encoding; bh=LrJQ81OQnCEJDCTRI1bdIMkvIXdbOY4niFVqWVBoYbo=; b=meTpc1Z8cn1bNeYUyVewhdIV7rdAzULghzuh8Qp/P2Poz+qP6HptO9S+NIrPabAmNJ a0OOLALbfBQIq3PL8kIMdKvh5Nzhg9A9RiEK2Dz0KVLlNaMtaWyDoXwwjpqGLqf1Xnv6 WlbxYX2wWWkhA5DxKnrz3Ufg+pAsz3hkbVwHoJ5v0213nTkt0ppdlQL9npefKNFuAAHJ clsTMuA/P+G8gSjxNRQDjcfFZuayz7I3fttyHoAAPtY1+W409BlNfD2ks8EkvLyPPBOK 3VqYuqcRP9eRlIXpsj6U1Rlh806Fn3sDFWq9FWjBoiKbggv9UESMk8LDOeSydARBz/KM Ou2g== X-Gm-Message-State: AOAM532m7/3QpxOjhNpCwmPUuCQvyen1lo8sSOh3DMH8j/hkZEKDPfjX cwI2amlM9NplaVHsbPstmHk= X-Received: by 2002:a17:906:3adb:: with SMTP id z27mr6774111ejd.291.1629489502870; Fri, 20 Aug 2021 12:58:22 -0700 (PDT) Received: from [192.168.43.131] (mob-176-243-162-112.net.vodafone.it. [176.243.162.112]) by smtp.gmail.com with ESMTPSA id o3sm3257847eju.123.2021.08.20.12.58.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Aug 2021 12:58:22 -0700 (PDT) Message-ID: Subject: Re: [PATCH] perf config: fix caching and memory leak in perf_home_perfconfig From: Riccardo Mancini To: Arnaldo Carvalho de Melo Cc: Ian Rogers , Namhyung Kim , 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 In-Reply-To: References: <20210820130817.740536-1-rickyman7@gmail.com> Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 Date: Fri, 20 Aug 2021 21:58:16 +0200 User-Agent: Evolution 3.40.3 (3.40.3-1.fc34) Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, On Fri, 2021-08-20 at 11:13 -0300, Arnaldo Carvalho de Melo wrote: > Em Fri, Aug 20, 2021 at 03:08:17PM +0200, Riccardo Mancini escreveu: > > 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(); > > humm, why keep the above failed test then? Sorry, I forgot about that, it should be removed. > > >         if (!config) > >                 failed = true; > > I.e. please check this: > > > diff --git a/tools/perf/util/config.c b/tools/perf/util/config.c > index 63d472b336de21d4..4fb5e90d7a57ae48 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; >   Looks good to me. Shall I resend it fixed? Thanks, Riccardo