test_fexit_bpf2bpf_common() can jump to the common cleanup path before the link array is allocated, for example if bpf_prog_get_info_by_fd() fails. The cleanup loop still indexes link[i] unconditionally, which can dereference a NULL pointer and hide the original failure. Guard the loop so the test reports the original failure instead. Signed-off-by: Zhixing Chen --- tools/testing/selftests/bpf/prog_tests/fexit_bpf2bpf.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/bpf/prog_tests/fexit_bpf2bpf.c b/tools/testing/selftests/bpf/prog_tests/fexit_bpf2bpf.c index 6262c81cdaa9..d2f2dcc0f2e1 100644 --- a/tools/testing/selftests/bpf/prog_tests/fexit_bpf2bpf.c +++ b/tools/testing/selftests/bpf/prog_tests/fexit_bpf2bpf.c @@ -164,8 +164,10 @@ static void test_fexit_bpf2bpf_common(const char *obj_file, goto close_prog; close_prog: - for (i = 0; i < prog_cnt; i++) - bpf_link__destroy(link[i]); + if (link) { + for (i = 0; i < prog_cnt; i++) + bpf_link__destroy(link[i]); + } bpf_object__close(obj); bpf_object__close(tgt_obj); free(link); base-commit: 71b75648d1a21c0a6379741d00f41086ec95f14a -- 2.34.1