Re: [PATCH 2/2] perf script: delete evlist when deleting session

From: Riccardo Mancini
Date: Tue Jun 22 2021 - 03:44:46 EST


Hi,

thanks for your comments.

On Mon, 2021-06-21 at 22:14 -0700, Ian Rogers wrote:
> On Mon, Jun 21, 2021 at 4:44 PM Riccardo Mancini <rickyman7@xxxxxxxxx> wrote:
> >
> > ASan reports a memory leak related to session->evlist never being deleted.
> > The evlist member is not deleted in perf_session__delete, so it should be
> > deleted separately.
> > This patch adds the missing deletion in perf-script.
> >
> > Signed-off-by: Riccardo Mancini <rickyman7@xxxxxxxxx>
> > ---
> >  tools/perf/builtin-script.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
> > index 1280cbfad4db..635a1d9cfc88 100644
> > --- a/tools/perf/builtin-script.c
> > +++ b/tools/perf/builtin-script.c
> > @@ -3991,7 +3991,7 @@ int cmd_script(int argc, const char **argv)
> >                 zfree(&script.ptime_range);
> >         }
> >
> > -       evlist__free_stats(session->evlist);
>
> Should this be removed?

Probably not. I originally thought this was already taken care of by
evlist__delete, but it's not. 
Oddly, this issue is not causing a memory leak in my simple test.

>
> > +       evlist__delete(session->evlist);
>
> If the perf session "owns" the evlist, would it be cleaner to add this
> to perf_session__delete?

I thought about that too, but that's not always true.
E.g., in perf-record, __cmd_record calls perf_session__delete,then cmd_record
calls evlist__delete on rec->evlist, which points to the same location to which
session->evlist pointed.

Thanks,
Riccardo

>
> Thanks,
> Ian
>
> >         perf_session__delete(session);
> >
> >         if (script_started)
> > --
> > 2.31.1
> >