* [PATCH] bpf, selftests: fix a resource leak in main()
@ 2024-07-11 7:44 Ma Ke
2024-07-11 7:52 ` Eduard Zingerman
0 siblings, 1 reply; 3+ messages in thread
From: Ma Ke @ 2024-07-11 7:44 UTC (permalink / raw)
To: ast, daniel, andrii, martin.lau, eddyz87, song, yonghong.song,
john.fastabend, kpsingh, sdf, haoluo, jolsa, mykolal, shuah
Cc: bpf, linux-kselftest, linux-kernel, Ma Ke
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@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
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] bpf, selftests: fix a resource leak in main()
2024-07-11 7:44 [PATCH] bpf, selftests: fix a resource leak in main() Ma Ke
@ 2024-07-11 7:52 ` Eduard Zingerman
0 siblings, 0 replies; 3+ messages in thread
From: Eduard Zingerman @ 2024-07-11 7:52 UTC (permalink / raw)
To: Ma Ke, ast, daniel, andrii, martin.lau, song, yonghong.song,
john.fastabend, kpsingh, sdf, haoluo, jolsa, mykolal, shuah
Cc: bpf, linux-kselftest, linux-kernel
On Thu, 2024-07-11 at 15:44 +0800, Ma Ke wrote:
> The requested resources should be closed before return in main(), otherwise
> resource leak will occur. Add a check of cgroup_fd and close().
Note: it is better to group related patches to a patch-set.
>
> Fixes: 4939b2847d26 ("bpf, selftests: Use single cgroup helpers for both test_sockmap/progs")
> Signed-off-by: Ma Ke <make24@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);
This is a standalone program, and Linux closes file descriptors on process exit,
why do you think it's necessary to close the fd here?
> return error;
> }
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH] bpf, selftests: fix a resource leak in main()
@ 2024-07-11 7:51 Ma Ke
0 siblings, 0 replies; 3+ messages in thread
From: Ma Ke @ 2024-07-11 7:51 UTC (permalink / raw)
To: andrii, eddyz87, mykolal, ast, daniel, martin.lau, song,
yonghong.song, john.fastabend, kpsingh, sdf, haoluo, jolsa,
shuah
Cc: bpf, linux-kselftest, linux-kernel, Ma Ke
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@iscas.ac.cn>
---
tools/testing/selftests/bpf/test_cgroup_storage.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/tools/testing/selftests/bpf/test_cgroup_storage.c b/tools/testing/selftests/bpf/test_cgroup_storage.c
index 0861ea60dcdd..4265f1348b6b 100644
--- a/tools/testing/selftests/bpf/test_cgroup_storage.c
+++ b/tools/testing/selftests/bpf/test_cgroup_storage.c
@@ -79,6 +79,8 @@ int main(int argc, char **argv)
}
cgroup_fd = cgroup_setup_and_join(TEST_CGROUP);
+ if (cgroup_fd < 0)
+ goto out;
/* Attach the bpf program */
if (bpf_prog_attach(prog_fd, cgroup_fd, BPF_CGROUP_INET_EGRESS, 0)) {
@@ -170,5 +172,7 @@ int main(int argc, char **argv)
free(percpu_value);
out:
+ if (cgroup_fd >= 0)
+ close(cgroup_fd);
return error;
}
--
2.25.1
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-07-11 7:52 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-07-11 7:44 [PATCH] bpf, selftests: fix a resource leak in main() Ma Ke
2024-07-11 7:52 ` Eduard Zingerman
2024-07-11 7:51 Ma Ke
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®