Re: [PATCH v2 1/2] perf parse-events: fix memory leaks found on parse_events
From: Ian Rogers
Date: Wed Apr 29 2020 - 13:43:50 EST
On Mon, Mar 23, 2020 at 3:59 AM Jiri Olsa <jolsa@xxxxxxxxxx> wrote:
>
> On Wed, Mar 18, 2020 at 07:31:00PM -0700, Ian Rogers wrote:
> > Memory leaks found by applying LLVM's libfuzzer on the parse_events
> > function.
> >
> > Signed-off-by: Ian Rogers <irogers@xxxxxxxxxx>
>
> Acked-by: Jiri Olsa <jolsa@xxxxxxxxxx>
>
> thanks,
> jirka
Ping.
> > ---
> > tools/perf/util/parse-events.c | 2 ++
> > tools/perf/util/parse-events.y | 3 ++-
> > 2 files changed, 4 insertions(+), 1 deletion(-)
> >
> > diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c
> > index 593b6b03785d..1e0bec5c0846 100644
> > --- a/tools/perf/util/parse-events.c
> > +++ b/tools/perf/util/parse-events.c
> > @@ -1482,6 +1482,8 @@ int parse_events_add_pmu(struct parse_events_state *parse_state,
> >
> > list_for_each_entry_safe(pos, tmp, &config_terms, list) {
> > list_del_init(&pos->list);
> > + if (pos->free_str)
> > + free(pos->val.str);
> > free(pos);
> > }
> > return -EINVAL;
> > diff --git a/tools/perf/util/parse-events.y b/tools/perf/util/parse-events.y
> > index 94f8bcd83582..8212cc771667 100644
> > --- a/tools/perf/util/parse-events.y
> > +++ b/tools/perf/util/parse-events.y
> > @@ -44,7 +44,7 @@ static void free_list_evsel(struct list_head* list_evsel)
> >
> > list_for_each_entry_safe(evsel, tmp, list_evsel, core.node) {
> > list_del_init(&evsel->core.node);
> > - perf_evsel__delete(evsel);
> > + evsel__delete(evsel);
> > }
> > free(list_evsel);
> > }
> > @@ -326,6 +326,7 @@ PE_NAME opt_pmu_config
> > }
> > parse_events_terms__delete($2);
> > parse_events_terms__delete(orig_terms);
> > + free(pattern);
> > free($1);
> > $$ = list;
> > #undef CLEANUP_YYABORT
> > --
> > 2.25.1.696.g5e7596f4ac-goog
> >
>