Re: [PATCH] sched_ext/selftests: Fix bpf_link leak on assertion failure
From: Tejun Heo
Date: Tue Mar 17 2026 - 14:21:48 EST
Hello,
In numa.c and rt_stall.c, the assertions check for SCX_EXIT_NONE â?? i.e.
the scheduler ran without error. bpf_link__destroy() triggers unregistration
which changes uei.kind to SCX_EXIT_UNREG, so moving it before the assertions
would make them always fail. Did you run the selftests after this patch?
A simpler approach would be using __attribute__((cleanup())) to auto-destroy
the link on any return path:
static inline void autolink_destroy(struct bpf_link **linkp)
{
if (*linkp)
bpf_link__destroy(*linkp);
}
#define __autolink __attribute__((cleanup(autolink_destroy)))
Then each test just does:
struct bpf_link *link __autolink = bpf_map__attach_struct_ops(...);
No reordering needed â?? the link auto-destroys on any return, including
early returns from assertion failures.
Thanks.
--
tejun