Re: [PATCH v5 08/10] perf tools: if pmu configuration fails free terms

Arnaldo Carvalho de Melo
2019-11-06T14:38:36Z

Em Wed, Nov 06, 2019 at 03:24:08PM +0100, Jiri Olsa escreveu:
> On Wed, Oct 30, 2019 at 03:34:46PM -0700, Ian Rogers wrote:
> > Avoid a memory leak when the configuration fails.
> >
> > Signed-off-by: Ian Rogers <irogers@google.com>
>
> Acked-by: Jiri Olsa <jolsa@kernel.org>

Thanks, applied,

- Arnaldo

> thanks,
> jirka
>
> > ---
> > tools/perf/util/parse-events.c | 9 ++++++++-
> > 1 file changed, 8 insertions(+), 1 deletion(-)
> >
> > diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c
> > index 578288c94d2a..a0a80f4e7038 100644
> > --- a/tools/perf/util/parse-events.c
> > +++ b/tools/perf/util/parse-events.c
> > @@ -1388,8 +1388,15 @@ int parse_events_add_pmu(struct parse_events_state *parse_state,
> > if (get_config_terms(head_config, &config_terms))
> > return -ENOMEM;
> >
> > - if (perf_pmu__config(pmu, &attr, head_config, parse_state->error))
> > + if (perf_pmu__config(pmu, &attr, head_config, parse_state->error)) {
> > + struct perf_evsel_config_term *pos, *tmp;
> > +
> > + list_for_each_entry_safe(pos, tmp, &config_terms, list) {
> > + list_del_init(&pos->list);
> > + free(pos);
> > + }
> > return -EINVAL;
> > + }
> >
> > evsel = __add_event(list, &parse_state->idx, &attr,
> > get_config_name(head_config), pmu,
> > --
> > 2.24.0.rc1.363.gb1bccd3e3d-goog
> >

--

- Arnaldo