summaryrefslogtreecommitdiff
path: root/samples
diff options
context:
space:
mode:
authorZhu Jun <zhujun2@cmss.chinamobile.com>2024-10-09 18:41:26 -0700
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2024-12-14 19:48:26 +0100
commit00c9f6e8259133bfb6dc2e528e0bbc4ca994ff57 (patch)
tree6dcb705070b727bd2a265dcf80253ddfc9ce478a /samples
parent86b66b8091c957a619d73bf58d0e227dcfc81171 (diff)
downloadlinux-00c9f6e8259133bfb6dc2e528e0bbc4ca994ff57.tar.gz
linux-00c9f6e8259133bfb6dc2e528e0bbc4ca994ff57.tar.bz2
linux-00c9f6e8259133bfb6dc2e528e0bbc4ca994ff57.zip
samples/bpf: Fix a resource leak
[ Upstream commit f3ef53174b23246fe9bc2bbc2542f3a3856fa1e2 ] The opened file should be closed in show_sockopts(), otherwise resource leak will occur that this problem was discovered by reading code Signed-off-by: Zhu Jun <zhujun2@cmss.chinamobile.com> Signed-off-by: Andrii Nakryiko <andrii@kernel.org> Link: https://lore.kernel.org/bpf/20241010014126.2573-1-zhujun2@cmss.chinamobile.com Signed-off-by: Sasha Levin <sashal@kernel.org>
Diffstat (limited to 'samples')
-rw-r--r--samples/bpf/test_cgrp2_sock.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/samples/bpf/test_cgrp2_sock.c b/samples/bpf/test_cgrp2_sock.c
index b0811da5a00f..3f56519a1ccd 100644
--- a/samples/bpf/test_cgrp2_sock.c
+++ b/samples/bpf/test_cgrp2_sock.c
@@ -174,8 +174,10 @@ static int show_sockopts(int family)
return 1;
}
- if (get_bind_to_device(sd, name, sizeof(name)) < 0)
+ if (get_bind_to_device(sd, name, sizeof(name)) < 0) {
+ close(sd);
return 1;
+ }
mark = get_somark(sd);
prio = get_priority(sd);