[<prev] [next>] [day] [month] [year] [list]
Message-Id: <20240711071859.2218494-1-make24@iscas.ac.cn>
Date: Thu, 11 Jul 2024 15:18:59 +0800
From: Ma Ke <make24@...as.ac.cn>
To: ast@...nel.org,
daniel@...earbox.net,
andrii@...nel.org,
martin.lau@...ux.dev,
eddyz87@...il.com,
song@...nel.org,
yonghong.song@...ux.dev,
john.fastabend@...il.com,
kpsingh@...nel.org,
sdf@...ichev.me,
haoluo@...gle.com,
jolsa@...nel.org,
mykolal@...com,
shuah@...nel.org,
rdna@...com
Cc: bpf@...r.kernel.org,
linux-kselftest@...r.kernel.org,
linux-kernel@...r.kernel.org,
Ma Ke <make24@...as.ac.cn>
Subject: [PATCH] selftests/bpf:fix a resource leak in main()
The requested resources should be closed before return in main(), otherwise
resource leak will occur. Add a check of cg_fd before close().
Fixes: 1f5fa9ab6e2e ("selftests/bpf: Test BPF_CGROUP_SYSCTL")
Signed-off-by: Ma Ke <make24@...as.ac.cn>
---
tools/testing/selftests/bpf/test_sysctl.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/tools/testing/selftests/bpf/test_sysctl.c b/tools/testing/selftests/bpf/test_sysctl.c
index bcdbd27f22f0..242246ba8d1e 100644
--- a/tools/testing/selftests/bpf/test_sysctl.c
+++ b/tools/testing/selftests/bpf/test_sysctl.c
@@ -1627,7 +1627,8 @@ int main(int argc, char **argv)
err:
err = -1;
out:
- close(cgfd);
+ if (cgfd >= 0)
+ close(cgfd);
cleanup_cgroup_environment();
return err;
}
--
2.25.1
Powered by blists - more mailing lists