The requested resources should be closed before return in run_tests(), otherwise resource leak will occur. Add a check of cg_fd before close().
Fixes: 1d436885b23b ("selftests/bpf: Selftest for sys_bind post-hooks.") Signed-off-by: Ma Ke make24@iscas.ac.cn --- tools/testing/selftests/bpf/test_sock.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/tools/testing/selftests/bpf/test_sock.c b/tools/testing/selftests/bpf/test_sock.c index 810c3740b2cc..bb5038fc15ac 100644 --- a/tools/testing/selftests/bpf/test_sock.c +++ b/tools/testing/selftests/bpf/test_sock.c @@ -550,7 +550,8 @@ int main(int argc, char **argv) err: err = -1; out: - close(cgfd); + if (cgfd >= 0) + close(cgfd); cleanup_cgroup_environment(); return err; }