perf trace: Free malloc'd trace fields on exit
authorRiccardo Mancini <rickyman7@gmail.com>
Thu, 15 Jul 2021 16:07:20 +0000 (18:07 +0200)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Thu, 15 Jul 2021 20:34:07 +0000 (17:34 -0300)
ASan reports several memory leaks running:

  # perf test "88: Check open filename arg using perf trace + vfs_getname"

The first of these leaks is related to struct trace fields never being
deallocated.

This patch adds the function trace__exit, which is called at the end of
cmd_trace, replacing the existing deallocation, which is now moved
inside the new function.

This function deallocates:

 - ev_qualifier
 - ev_qualifier_ids.entries
 - syscalls.table
 - sctbl
 - perfconfig_events

Signed-off-by: Riccardo Mancini <rickyman7@gmail.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lore.kernel.org/lkml/de5945ed5c0cb882cbfa3268567d0bff460ff016.1626343282.git.rickyman7@gmail.com
[ Removed needless initialization to zero, missing named initializers are zeroed by the compiler ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/builtin-trace.c

index 7ec18ff..e239e32 100644 (file)
@@ -4701,6 +4701,15 @@ out:
        return err;
 }
 
+static void trace__exit(struct trace *trace)
+{
+       strlist__delete(trace->ev_qualifier);
+       free(trace->ev_qualifier_ids.entries);
+       free(trace->syscalls.table);
+       syscalltbl__delete(trace->sctbl);
+       zfree(&trace->perfconfig_events);
+}
+
 int cmd_trace(int argc, const char **argv)
 {
        const char *trace_usage[] = {
@@ -5135,6 +5144,6 @@ out_close:
        if (output_name != NULL)
                fclose(trace.output);
 out:
-       zfree(&trace.perfconfig_events);
+       trace__exit(&trace);
        return err;
 }