All of lore.kernel.org
 help / color / mirror / Atom feed
From: Riccardo Mancini <rickyman7@gmail.com>
To: Arnaldo Carvalho de Melo <arnaldo.melo@gmail.com>
Cc: Ian Rogers <irogers@google.com>,
	Namhyung Kim <namhyung@kernel.org>, Jiri Olsa <jolsa@kernel.org>,
	Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@redhat.com>,
	Mark Rutland <mark.rutland@arm.com>,
	Alexander Shishkin <alexander.shishkin@linux.intel.com>,
	Jiri Olsa <jolsa@redhat.com>, Jin Yao <yao.jin@linux.intel.com>,
	Song Liu <song@kernel.org>,
	linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] perf config: fix caching and memory leak in perf_home_perfconfig
Date: Fri, 20 Aug 2021 21:58:16 +0200	[thread overview]
Message-ID: <a647993d9eff9fab20196661ba2a153c7258e569.camel@gmail.com> (raw)
In-Reply-To: <YR+4kOwuIoPsz2Rw@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 <jolsa@kernel.org>
> > Fixes: f5f03e19ce14fc31 ("perf config: Add perf_home_perfconfig function")
> > Signed-off-by: Riccardo Mancini <rickyman7@gmail.com>
> > ---
> >  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


  reply	other threads:[~2021-08-20 19:58 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-20 13:08 [PATCH] perf config: fix caching and memory leak in perf_home_perfconfig Riccardo Mancini
2021-08-20 14:13 ` Arnaldo Carvalho de Melo
2021-08-20 19:58   ` Riccardo Mancini [this message]
2021-08-24 19:26     ` Arnaldo Carvalho de Melo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=a647993d9eff9fab20196661ba2a153c7258e569.camel@gmail.com \
    --to=rickyman7@gmail.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=arnaldo.melo@gmail.com \
    --cc=irogers@google.com \
    --cc=jolsa@kernel.org \
    --cc=jolsa@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.org \
    --cc=song@kernel.org \
    --cc=yao.jin@linux.intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.