Skip to content

Commit 6c7f0ab

Browse files
Manciukicacmel
authored andcommitted
perf trace: Free malloc'd trace fields on exit
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>
1 parent f8cbb0f commit 6c7f0ab

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

tools/perf/builtin-trace.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4701,6 +4701,15 @@ static int trace__config(const char *var, const char *value, void *arg)
47014701
return err;
47024702
}
47034703

4704+
static void trace__exit(struct trace *trace)
4705+
{
4706+
strlist__delete(trace->ev_qualifier);
4707+
free(trace->ev_qualifier_ids.entries);
4708+
free(trace->syscalls.table);
4709+
syscalltbl__delete(trace->sctbl);
4710+
zfree(&trace->perfconfig_events);
4711+
}
4712+
47044713
int cmd_trace(int argc, const char **argv)
47054714
{
47064715
const char *trace_usage[] = {
@@ -5135,6 +5144,6 @@ int cmd_trace(int argc, const char **argv)
51355144
if (output_name != NULL)
51365145
fclose(trace.output);
51375146
out:
5138-
zfree(&trace.perfconfig_events);
5147+
trace__exit(&trace);
51395148
return err;
51405149
}

0 commit comments

Comments
 (0)