Skip to content

Commit eda9e47

Browse files
captain5050namhyung
authored andcommitted
perf trace: Add missed freeing of ordered events and thread
Caught by leak sanitizer running "perf trace BTF general tests". Make the ordered_events initialization unconditional and early so that trace__exit cleanup is simple - ordered_events__init doesn't allocate and just sets up 4 values and inits 3 list heads. Signed-off-by: Ian Rogers <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Namhyung Kim <[email protected]>
1 parent 9a79c50 commit eda9e47

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

tools/perf/builtin-trace.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5361,6 +5361,7 @@ static int trace__config(const char *var, const char *value, void *arg)
53615361

53625362
static void trace__exit(struct trace *trace)
53635363
{
5364+
thread__zput(trace->current);
53645365
strlist__delete(trace->ev_qualifier);
53655366
zfree(&trace->ev_qualifier_ids.entries);
53665367
if (trace->syscalls.table) {
@@ -5371,6 +5372,7 @@ static void trace__exit(struct trace *trace)
53715372
zfree(&trace->perfconfig_events);
53725373
evlist__delete(trace->evlist);
53735374
trace->evlist = NULL;
5375+
ordered_events__free(&trace->oe.data);
53745376
#ifdef HAVE_LIBBPF_SUPPORT
53755377
btf__free(trace->btf);
53765378
trace->btf = NULL;
@@ -5520,6 +5522,9 @@ int cmd_trace(int argc, const char **argv)
55205522
sigchld_act.sa_sigaction = sighandler_chld;
55215523
sigaction(SIGCHLD, &sigchld_act, NULL);
55225524

5525+
ordered_events__init(&trace.oe.data, ordered_events__deliver_event, &trace);
5526+
ordered_events__set_copy_on_queue(&trace.oe.data, true);
5527+
55235528
trace.evlist = evlist__new();
55245529

55255530
if (trace.evlist == NULL) {
@@ -5678,11 +5683,6 @@ int cmd_trace(int argc, const char **argv)
56785683
trace__load_vmlinux_btf(&trace);
56795684
}
56805685

5681-
if (trace.sort_events) {
5682-
ordered_events__init(&trace.oe.data, ordered_events__deliver_event, &trace);
5683-
ordered_events__set_copy_on_queue(&trace.oe.data, true);
5684-
}
5685-
56865686
/*
56875687
* If we are augmenting syscalls, then combine what we put in the
56885688
* __augmented_syscalls__ BPF map with what is in the

0 commit comments

Comments
 (0)