[PATCH v6 13/26] perf trace: Destroy the BPF skeleton if it fails to load

From: Ian Rogers

Date: Mon Sep 28 2026 - 14:37:46 EST


If augmented_syscalls__prepare() fails to load the skeleton, perf trace
falls back to unaugmented tracing but leaves the skeleton in place.
augmented_syscalls__set_filter_pids() then writes to maps that were
never created and fails with -ENOENT, so a system wide session, or one
using --filter-pids, exits with "Not enough memory to run!".

Destroy the skeleton on failure and clear the pointer, so the setters
do nothing.

Assisted-by: Antigravity:gemini-3.1-pro
Signed-off-by: Ian Rogers <irogers@xxxxxxxxxx>
---
tools/perf/util/bpf_trace_augment.c | 2 ++
1 file changed, 2 insertions(+)

diff --git a/tools/perf/util/bpf_trace_augment.c b/tools/perf/util/bpf_trace_augment.c
index 7087849031e6..daa79a55c795 100644
--- a/tools/perf/util/bpf_trace_augment.c
+++ b/tools/perf/util/bpf_trace_augment.c
@@ -37,6 +37,7 @@ int augmented_syscalls__prepare(void)
if (err < 0) {
libbpf_strerror(err, buf, sizeof(buf));
pr_debug("Failed to load augmented syscalls BPF skeleton: %s\n", buf);
+ augmented_syscalls__cleanup();
return err;
}

@@ -146,4 +147,5 @@ struct bpf_program *augmented_syscalls__find_by_title(const char *name)
void augmented_syscalls__cleanup(void)
{
augmented_raw_syscalls_bpf__destroy(skel);
+ skel = NULL;
}
--
2.56.0.rc1.315.gc6ed9934b7-goog