2020-07-03 09:29:58

by Zheng Zengkai

[permalink] [raw]
Subject: [PATCH -next] perf util: Fix memory leak in __parse_regs()

when using perf record option '-I' or '--user-regs='
along with argument '?' to list available register names,
memory of variable 'os' allocated by strdup() needs to be released
before __parse_regs() returns, otherwise memory leak will occur.

Fixes: bcc84ec65ad1 ("perf record: Add ability to name registers to record")
Signed-off-by: Zheng Zengkai <[email protected]>
---
tools/perf/util/parse-regs-options.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/perf/util/parse-regs-options.c b/tools/perf/util/parse-regs-options.c
index e687497b3aac..a4a100425b3a 100644
--- a/tools/perf/util/parse-regs-options.c
+++ b/tools/perf/util/parse-regs-options.c
@@ -54,7 +54,7 @@ __parse_regs(const struct option *opt, const char *str, int unset, bool intr)
#endif
fputc('\n', stderr);
/* just printing available regs */
- return -1;
+ goto error;
}
#ifdef HAVE_PERF_REGS_SUPPORT
for (r = sample_reg_masks; r->name; r++) {
--
2.20.1


2020-07-03 10:35:03

by Jiri Olsa

[permalink] [raw]
Subject: Re: [PATCH -next] perf util: Fix memory leak in __parse_regs()

On Fri, Jul 03, 2020 at 05:33:44PM +0800, Zheng Zengkai wrote:
> when using perf record option '-I' or '--user-regs='
> along with argument '?' to list available register names,
> memory of variable 'os' allocated by strdup() needs to be released
> before __parse_regs() returns, otherwise memory leak will occur.
>
> Fixes: bcc84ec65ad1 ("perf record: Add ability to name registers to record")
> Signed-off-by: Zheng Zengkai <[email protected]>

Acked-by: Jiri Olsa <[email protected]>

thanks,
jirka

> ---
> tools/perf/util/parse-regs-options.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/tools/perf/util/parse-regs-options.c b/tools/perf/util/parse-regs-options.c
> index e687497b3aac..a4a100425b3a 100644
> --- a/tools/perf/util/parse-regs-options.c
> +++ b/tools/perf/util/parse-regs-options.c
> @@ -54,7 +54,7 @@ __parse_regs(const struct option *opt, const char *str, int unset, bool intr)
> #endif
> fputc('\n', stderr);
> /* just printing available regs */
> - return -1;
> + goto error;
> }
> #ifdef HAVE_PERF_REGS_SUPPORT
> for (r = sample_reg_masks; r->name; r++) {
> --
> 2.20.1
>

2020-11-27 08:52:49

by Zheng Zengkai

[permalink] [raw]
Subject: Re: [PATCH -next] perf util: Fix memory leak in __parse_regs()

Ping...

> On Fri, Jul 03, 2020 at 05:33:44PM +0800, Zheng Zengkai wrote:
>> when using perf record option '-I' or '--user-regs='
>> along with argument '?' to list available register names,
>> memory of variable 'os' allocated by strdup() needs to be released
>> before __parse_regs() returns, otherwise memory leak will occur.
>>
>> Fixes: bcc84ec65ad1 ("perf record: Add ability to name registers to record")
>> Signed-off-by: Zheng Zengkai <[email protected]>
> Acked-by: Jiri Olsa <[email protected]>
>
> thanks,
> jirka
>
>> ---
>> tools/perf/util/parse-regs-options.c | 2 +-
>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/tools/perf/util/parse-regs-options.c b/tools/perf/util/parse-regs-options.c
>> index e687497b3aac..a4a100425b3a 100644
>> --- a/tools/perf/util/parse-regs-options.c
>> +++ b/tools/perf/util/parse-regs-options.c
>> @@ -54,7 +54,7 @@ __parse_regs(const struct option *opt, const char *str, int unset, bool intr)
>> #endif
>> fputc('\n', stderr);
>> /* just printing available regs */
>> - return -1;
>> + goto error;
>> }
>> #ifdef HAVE_PERF_REGS_SUPPORT
>> for (r = sample_reg_masks; r->name; r++) {
>> --
>> 2.20.1
>>
> .
>

2020-12-07 16:49:25

by Arnaldo Carvalho de Melo

[permalink] [raw]
Subject: Re: [PATCH -next] perf util: Fix memory leak in __parse_regs()

Em Fri, Nov 27, 2020 at 03:45:40PM +0800, Zheng Zengkai escreveu:
> Ping...

Thanks, applied.

- Arnaldo

> > On Fri, Jul 03, 2020 at 05:33:44PM +0800, Zheng Zengkai wrote:
> > > when using perf record option '-I' or '--user-regs='
> > > along with argument '?' to list available register names,
> > > memory of variable 'os' allocated by strdup() needs to be released
> > > before __parse_regs() returns, otherwise memory leak will occur.
> > >
> > > Fixes: bcc84ec65ad1 ("perf record: Add ability to name registers to record")
> > > Signed-off-by: Zheng Zengkai <[email protected]>
> > Acked-by: Jiri Olsa <[email protected]>
> >
> > thanks,
> > jirka
> >
> > > ---
> > > tools/perf/util/parse-regs-options.c | 2 +-
> > > 1 file changed, 1 insertion(+), 1 deletion(-)
> > >
> > > diff --git a/tools/perf/util/parse-regs-options.c b/tools/perf/util/parse-regs-options.c
> > > index e687497b3aac..a4a100425b3a 100644
> > > --- a/tools/perf/util/parse-regs-options.c
> > > +++ b/tools/perf/util/parse-regs-options.c
> > > @@ -54,7 +54,7 @@ __parse_regs(const struct option *opt, const char *str, int unset, bool intr)
> > > #endif
> > > fputc('\n', stderr);
> > > /* just printing available regs */
> > > - return -1;
> > > + goto error;
> > > }
> > > #ifdef HAVE_PERF_REGS_SUPPORT
> > > for (r = sample_reg_masks; r->name; r++) {
> > > --
> > > 2.20.1
> > >
> > .
> >

--

- Arnaldo