Re: [PATCH bpf] selftests/bpf: Fix resource leak in serial_test_wq on attach failure
From: Yonghong Song
Date: Wed Jan 21 2026 - 18:06:01 EST
On 1/21/26 9:49 AM, Kery Qi wrote:
Hi,
Thank you for the review.
You are completely right regarding wq__open_and_load(): if it fails,
it returns NULL and performs its own cleanup, so an immediate return
is correct there.
However, my concern is about the next step: wq__attach(wq_skel).
If wq__open_and_load() succeeds, wq_skel is allocated. If wq__attach()
subsequently fails, the original code returns immediately without
calling wq__destroy(wq_skel), which causes a memory leak of the
skeleton object.
The proposed goto clean_up is intended to ensure wq__destroy(wq_skel)
is called specifically when wq__attach() fails.
Does that make sense?
Yes.
Best regards,
Kery
Yonghong Song <yonghong.song@xxxxxxxxx> 于2026年1月21日周三 23:45写道:
On 1/21/26 1:41 AM, Kery Qi wrote:
When wq__attach() fails, serial_test_wq() returns early without callingAcked-by: Yonghong Song <yonghong.song@xxxxxxxxx>
wq__destroy(), leaking the skeleton resources allocated by
wq__open_and_load(). This causes ASAN leak reports in selftests runs.
Fix this by jumping to a common clean_up label that calls wq__destroy()
on all exit paths after successful open_and_load.
Note that the early return after wq__open_and_load() failure is correct
and doesn't need fixing, since that function returns NULL on failure
(after internally cleaning up any partial allocations).
Fixes: 8290dba51910 ("selftests/bpf: wq: add bpf_wq_start() checks")
Signed-off-by: Kery Qi <qikeyu2017@xxxxxxxxx>