Skip to content

Commit 2bb270a

Browse files
theihorAlexei Starovoitov
authored andcommitted
selftests/bpf: Free bpf_object in test_sysctl
ASAN reported a resource leak due to the bpf_object not being tracked in test_sysctl. Add obj field to struct sysctl_test to properly clean it up. Acked-by: Eduard Zingerman <eddyz87@gmail.com> Signed-off-by: Ihor Solodrai <ihor.solodrai@linux.dev> Link: https://lore.kernel.org/r/20260223190736.649171-17-ihor.solodrai@linux.dev Signed-off-by: Alexei Starovoitov <ast@kernel.org>
1 parent 71dca29 commit 2bb270a

1 file changed

Lines changed: 3 additions & 0 deletions

File tree

tools/testing/selftests/bpf/prog_tests/test_sysctl.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ struct sysctl_test {
2727
OP_EPERM,
2828
SUCCESS,
2929
} result;
30+
struct bpf_object *obj;
3031
};
3132

3233
static struct sysctl_test tests[] = {
@@ -1471,6 +1472,7 @@ static int load_sysctl_prog_file(struct sysctl_test *test)
14711472
return -1;
14721473
}
14731474

1475+
test->obj = obj;
14741476
return prog_fd;
14751477
}
14761478

@@ -1573,6 +1575,7 @@ static int run_test_case(int cgfd, struct sysctl_test *test)
15731575
/* Detaching w/o checking return code: best effort attempt. */
15741576
if (progfd != -1)
15751577
bpf_prog_detach(cgfd, atype);
1578+
bpf_object__close(test->obj);
15761579
close(progfd);
15771580
printf("[%s]\n", err ? "FAIL" : "PASS");
15781581
return err;

0 commit comments

Comments
 (0)