[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <ZWSXCwrx5BUpYGi/@kernel.org>
Date: Mon, 27 Nov 2023 10:18:03 -0300
From: Arnaldo Carvalho de Melo <acme@...nel.org>
To: Ingo Molnar <mingo@...nel.org>
Cc: Peter Zijlstra <peterz@...radead.org>,
zhaimingbing <zhaimingbing@...s.chinamobile.com>,
Namhyung Kim <namhyung@...nel.org>,
Ingo Molnar <mingo@...hat.com>,
Mark Rutland <mark.rutland@....com>,
Alexander Shishkin <alexander.shishkin@...ux.intel.com>,
Jiri Olsa <jolsa@...nel.org>, Ian Rogers <irogers@...gle.com>,
Adrian Hunter <adrian.hunter@...el.com>,
Sean Christopherson <seanjc@...gle.com>,
Li Dong <lidong@...o.com>, linux-perf-users@...r.kernel.org,
linux-kernel@...r.kernel.org
Subject: Re: [PATCH] perf lock: Fix a memory leak on an error path
Em Fri, Nov 24, 2023 at 01:56:35PM +0100, Ingo Molnar escreveu:
>
> * Peter Zijlstra <peterz@...radead.org> wrote:
>
> > On Fri, Nov 24, 2023 at 05:26:57PM +0800, zhaimingbing wrote:
> > > if a strdup-ed string is NULL,the allocated memory needs freeing.
> > >
> > > Signed-off-by: zhaimingbing <zhaimingbing@...s.chinamobile.com>
> > > ---
> > > tools/perf/builtin-lock.c | 4 +++-
> > > 1 file changed, 3 insertions(+), 1 deletion(-)
> > >
> > > diff --git a/tools/perf/builtin-lock.c b/tools/perf/builtin-lock.c
> > > index b141f2134..086041bcb 100644
> > > --- a/tools/perf/builtin-lock.c
> > > +++ b/tools/perf/builtin-lock.c
> > > @@ -2228,8 +2228,10 @@ static int __cmd_record(int argc, const char **argv)
> > > else
> > > ev_name = strdup(contention_tracepoints[j].name);
> > >
> > > - if (!ev_name)
> > > + if (!ev_name) {
> > > + free(rec_argv);
> > > return -ENOMEM;
> > > + }
> >
> > Isn't this an error path straight into exit?
>
> It increases the quality of implementation if resources are free()d
> consistently regardless of whether the task is going to exit() immediately,
> for example it makes it easier to validate perf for the lack of memory
> leaks with Valgrind.
I'm taking this positive comment about the patch as an Acked-by, ok?
- Arnaldo
Powered by blists - more mailing lists