2023-11-20 11:29:02

by zhaimingbing

[permalink] [raw]
Subject: [PATCH] perf script perl: Fail check on dynamic allocation

Return ENOMEM when dynamic allocation failed.

Signed-off-by: zhaimingbing <[email protected]>
---
tools/perf/util/scripting-engines/trace-event-perl.c | 3 +++
1 file changed, 3 insertions(+)

diff --git a/tools/perf/util/scripting-engines/trace-event-perl.c b/tools/perf/util/scripting-engines/trace-event-perl.c
index 603091317..b072ac5d3 100644
--- a/tools/perf/util/scripting-engines/trace-event-perl.c
+++ b/tools/perf/util/scripting-engines/trace-event-perl.c
@@ -490,6 +490,9 @@ static int perl_start_script(const char *script, int argc, const char **argv,
scripting_context->session = session;

command_line = malloc((argc + 2) * sizeof(const char *));
+ if (!command_line)
+ return -ENOMEM;
+
command_line[0] = "";
command_line[1] = script;
for (i = 2; i < argc + 2; i++)
--
2.33.0




2023-11-21 00:31:54

by Ian Rogers

[permalink] [raw]
Subject: Re: [PATCH] perf script perl: Fail check on dynamic allocation

On Mon, Nov 20, 2023 at 3:24 AM zhaimingbing
<[email protected]> wrote:
>
> Return ENOMEM when dynamic allocation failed.
>
> Signed-off-by: zhaimingbing <[email protected]>

Reviewed-by: Ian Rogers <[email protected]>

Thanks,
Ian

> ---
> tools/perf/util/scripting-engines/trace-event-perl.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/tools/perf/util/scripting-engines/trace-event-perl.c b/tools/perf/util/scripting-engines/trace-event-perl.c
> index 603091317..b072ac5d3 100644
> --- a/tools/perf/util/scripting-engines/trace-event-perl.c
> +++ b/tools/perf/util/scripting-engines/trace-event-perl.c
> @@ -490,6 +490,9 @@ static int perl_start_script(const char *script, int argc, const char **argv,
> scripting_context->session = session;
>
> command_line = malloc((argc + 2) * sizeof(const char *));
> + if (!command_line)
> + return -ENOMEM;
> +
> command_line[0] = "";
> command_line[1] = script;
> for (i = 2; i < argc + 2; i++)
> --
> 2.33.0
>
>
>
>

2023-11-21 17:23:37

by Arnaldo Carvalho de Melo

[permalink] [raw]
Subject: Re: [PATCH] perf script perl: Fail check on dynamic allocation

Em Mon, Nov 20, 2023 at 04:30:28PM -0800, Ian Rogers escreveu:
> On Mon, Nov 20, 2023 at 3:24 AM zhaimingbing
> <[email protected]> wrote:
> >
> > Return ENOMEM when dynamic allocation failed.
> >
> > Signed-off-by: zhaimingbing <[email protected]>
>
> Reviewed-by: Ian Rogers <[email protected]>

Thanks, applied to perf-tools-next.

- Arnaldo


> Thanks,
> Ian
>
> > ---
> > tools/perf/util/scripting-engines/trace-event-perl.c | 3 +++
> > 1 file changed, 3 insertions(+)
> >
> > diff --git a/tools/perf/util/scripting-engines/trace-event-perl.c b/tools/perf/util/scripting-engines/trace-event-perl.c
> > index 603091317..b072ac5d3 100644
> > --- a/tools/perf/util/scripting-engines/trace-event-perl.c
> > +++ b/tools/perf/util/scripting-engines/trace-event-perl.c
> > @@ -490,6 +490,9 @@ static int perl_start_script(const char *script, int argc, const char **argv,
> > scripting_context->session = session;
> >
> > command_line = malloc((argc + 2) * sizeof(const char *));
> > + if (!command_line)
> > + return -ENOMEM;
> > +
> > command_line[0] = "";
> > command_line[1] = script;
> > for (i = 2; i < argc + 2; i++)
> > --
> > 2.33.0
> >
> >
> >
> >

--

- Arnaldo