[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 Wireless]     [Linux Kernel]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [Share Photos]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Samba]     [Device Mapper]

  Powered by Linux