The requested resources should be closed before return in main(), otherwise
resource leak will occur. Add a check of cgroup_fd and close().

Fixes: 4939b2847d26 ("bpf, selftests: Use single cgroup helpers for both 
test_sockmap/progs")
Signed-off-by: Ma Ke <mak...@iscas.ac.cn>
---
 tools/testing/selftests/bpf/test_dev_cgroup.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/tools/testing/selftests/bpf/test_dev_cgroup.c 
b/tools/testing/selftests/bpf/test_dev_cgroup.c
index adeaf63cb6fa..e97fc061fab2 100644
--- a/tools/testing/selftests/bpf/test_dev_cgroup.c
+++ b/tools/testing/selftests/bpf/test_dev_cgroup.c
@@ -81,5 +81,7 @@ int main(int argc, char **argv)
        cleanup_cgroup_environment();
 
 out:
+       if (cgroup_fd >= 0)
+               close(cgroup_fd);
        return error;
 }
-- 
2.25.1


Reply via email to