Skip to content

Commit

Permalink
perf trace: Free syscall tp fields in evsel->priv
Browse files Browse the repository at this point in the history
ASan reports several memory leaks running:

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

The third of these leaks is related to evsel->priv fields of sycalls
never being deallocated.

This patch adds the function evlist__free_syscall_tp_fields which
iterates over all evsels in evlist, matching syscalls, and calling the
missing frees.

This new function is called at the end of trace__run, right before
calling evlist__delete.

Signed-off-by: Riccardo Mancini <[email protected]>
Cc: Ian Rogers <[email protected]>
Cc: Jiri Olsa <[email protected]>
Cc: Mark Rutland <[email protected]>
Cc: Namhyung Kim <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Link: http://lore.kernel.org/lkml/46526611904ec5ff2768b59014e3afce8e0197d1.1626343282.git.rickyman7@gmail.com
Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
  • Loading branch information
Manciukic authored and acmel committed Jul 15, 2021
1 parent f2ebf8f commit 3cb4d5e
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion tools/perf/builtin-trace.c
Original file line number Diff line number Diff line change
Expand Up @@ -3103,6 +3103,21 @@ static struct evsel *evsel__new_pgfault(u64 config)
return evsel;
}

static void evlist__free_syscall_tp_fields(struct evlist *evlist)
{
struct evsel *evsel;

evlist__for_each_entry(evlist, evsel) {
struct evsel_trace *et = evsel->priv;

if (!et || !evsel->tp_format || strcmp(evsel->tp_format->system, "syscalls"))
continue;

free(et->fmt);
free(et);
}
}

static void trace__handle_event(struct trace *trace, union perf_event *event, struct perf_sample *sample)
{
const u32 type = event->header.type;
Expand Down Expand Up @@ -4138,7 +4153,7 @@ static int trace__run(struct trace *trace, int argc, const char **argv)

out_delete_evlist:
trace__symbols__exit(trace);

evlist__free_syscall_tp_fields(evlist);
evlist__delete(evlist);
cgroup__put(trace->cgroup);
trace->evlist = NULL;
Expand Down

0 comments on commit 3cb4d5e

Please sign in to comment.