[PATCH] bpf, selftests: fix a resource leak in main()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 <make24@xxxxxxxxxxx>
---
 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





[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux