mirror of
https://github.com/torvalds/linux.git
synced 2026-09-23 05:04:02 +02:00
perf tools: Fix sb_evlist leaks in top and record
Fix a memory leak in cmd_top() where top.sb_evlist was not freed if
evlist__add_bpf_sb_event() fails. Note that evlist__start_sb_thread() and
evlist__stop_sb_thread() take ownership of the evlist and free it, so
we must only free it if we fail before starting the thread. Also set
top.sb_evlist to NULL to prevent use-after-free bugs.
Apply the same fix to builtin-record.c to avoid leaking rec->sb_evlist
and calling pthread_join on uninitialized threads in the error path.
Assisted-by: Antigravity:gemini-3.1-pro
Fixes: b38d85ef49 ("perf bpf: Decouple creating the evlist from adding the SB event")
Signed-off-by: Ian Rogers <irogers@google.com>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
This commit is contained in:
parent
340641a4b5
commit
08e96e3c73
|
|
@ -2258,6 +2258,8 @@ static int record__setup_sb_evlist(struct record *rec)
|
|||
|
||||
if (evlist__add_bpf_sb_event(rec->sb_evlist, perf_session__env(rec->session))) {
|
||||
pr_err("Couldn't ask for PERF_RECORD_BPF_EVENT side band events.\n.");
|
||||
evlist__put(rec->sb_evlist);
|
||||
rec->sb_evlist = NULL;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1881,6 +1881,8 @@ int cmd_top(int argc, const char **argv)
|
|||
if (evlist__add_bpf_sb_event(top.sb_evlist, &host_env)) {
|
||||
pr_err("Couldn't ask for PERF_RECORD_BPF_EVENT side band events.\n.");
|
||||
status = -EINVAL;
|
||||
evlist__put(top.sb_evlist);
|
||||
top.sb_evlist = NULL;
|
||||
goto out_put_evlist;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user