[PATCH] selftests/bpf: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 cgfd before close().

Fixes: 5ecd8c22739b ("selftests/bpf: Selftest for bpf_skb_ancestor_cgroup_id")
Signed-off-by: Ma Ke <make24@xxxxxxxxxxx>
---
 tools/testing/selftests/bpf/test_skb_cgroup_id_user.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/tools/testing/selftests/bpf/test_skb_cgroup_id_user.c b/tools/testing/selftests/bpf/test_skb_cgroup_id_user.c
index ed518d075d1d..f84faddd72e6 100644
--- a/tools/testing/selftests/bpf/test_skb_cgroup_id_user.c
+++ b/tools/testing/selftests/bpf/test_skb_cgroup_id_user.c
@@ -176,7 +176,8 @@ int main(int argc, char **argv)
 err:
 	err = -1;
 out:
-	close(cgfd);
+	if (cgfd >= 0)
+		close(cgfd);
 	cleanup_cgroup_environment();
 	printf("[%s]\n", err ? "FAIL" : "PASS");
 	return err;
-- 
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