* [PATCH AUTOSEL 4.19 02/21] samples/bpf: Fix a resource leak
[not found] <20241124135709.3351371-1-sashal@kernel.org>
@ 2024-11-24 13:56 ` Sasha Levin
2024-12-02 12:12 ` Pavel Machek
0 siblings, 1 reply; 2+ messages in thread
From: Sasha Levin @ 2024-11-24 13:56 UTC (permalink / raw)
To: linux-kernel, stable
Cc: Zhu Jun, Andrii Nakryiko, Sasha Levin, ast, daniel, bpf
From: Zhu Jun <zhujun2@cmss.chinamobile.com>
[ 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>
---
samples/bpf/test_cgrp2_sock.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/samples/bpf/test_cgrp2_sock.c b/samples/bpf/test_cgrp2_sock.c
index b0811da5a00f3..3f56519a1ccd7 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);
--
2.43.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH AUTOSEL 4.19 02/21] samples/bpf: Fix a resource leak
2024-11-24 13:56 ` [PATCH AUTOSEL 4.19 02/21] samples/bpf: Fix a resource leak Sasha Levin
@ 2024-12-02 12:12 ` Pavel Machek
0 siblings, 0 replies; 2+ messages in thread
From: Pavel Machek @ 2024-12-02 12:12 UTC (permalink / raw)
To: Sasha Levin
Cc: linux-kernel, stable, Zhu Jun, Andrii Nakryiko, ast, daniel, bpf
[-- Attachment #1: Type: text/plain, Size: 812 bytes --]
Hi!
> [ 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
Well, code exits when this fails, so there's really no leak.
Best regards,
Pavel
> +++ 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);
--
DENX Software Engineering GmbH, Managing Director: Erika Unter
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-12-02 12:12 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <20241124135709.3351371-1-sashal@kernel.org>
2024-11-24 13:56 ` [PATCH AUTOSEL 4.19 02/21] samples/bpf: Fix a resource leak Sasha Levin
2024-12-02 12:12 ` Pavel Machek
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox