Skip to content

Commit f2ebf8f

Browse files
Manciukicacmel
authored andcommitted
perf trace: Free syscall->arg_fmt
ASan reports several memory leaks running: # perf test "88: Check open filename arg using perf trace + vfs_getname" The second of these leaks is caused by the arg_fmt field of syscall not being deallocated. This patch adds a new function syscall__exit which is called on all syscalls.table entries in trace__exit, which will free the arg_fmt field. 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/d68f25c043d30464ac9fa79c3399e18f429bca82.1626343282.git.rickyman7@gmail.com Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent 6c7f0ab commit f2ebf8f

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

tools/perf/builtin-trace.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2266,6 +2266,14 @@ static void *syscall__augmented_args(struct syscall *sc, struct perf_sample *sam
22662266
return augmented_args;
22672267
}
22682268

2269+
static void syscall__exit(struct syscall *sc)
2270+
{
2271+
if (!sc)
2272+
return;
2273+
2274+
free(sc->arg_fmt);
2275+
}
2276+
22692277
static int trace__sys_enter(struct trace *trace, struct evsel *evsel,
22702278
union perf_event *event __maybe_unused,
22712279
struct perf_sample *sample)
@@ -4703,9 +4711,15 @@ static int trace__config(const char *var, const char *value, void *arg)
47034711

47044712
static void trace__exit(struct trace *trace)
47054713
{
4714+
int i;
4715+
47064716
strlist__delete(trace->ev_qualifier);
47074717
free(trace->ev_qualifier_ids.entries);
4708-
free(trace->syscalls.table);
4718+
if (trace->syscalls.table) {
4719+
for (i = 0; i <= trace->sctbl->syscalls.max_id; i++)
4720+
syscall__exit(&trace->syscalls.table[i]);
4721+
free(trace->syscalls.table);
4722+
}
47094723
syscalltbl__delete(trace->sctbl);
47104724
zfree(&trace->perfconfig_events);
47114725
}

0 commit comments

Comments
 (0)