public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] samples/bpf: Fix a resource leak
@ 2024-10-10  1:41 Zhu Jun
  2024-10-11  2:20 ` patchwork-bot+netdevbpf
  0 siblings, 1 reply; 2+ messages in thread
From: Zhu Jun @ 2024-10-10  1:41 UTC (permalink / raw)
  To: eddyz87
  Cc: song, yonghong.song, john.fastabend, kpsingh, sdf, haoluo, jolsa,
	bpf, linux-kernel, martin.lau, Zhu Jun

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>
---
 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 a0811df888f4..8ca2a445ffa1 100644
--- a/samples/bpf/test_cgrp2_sock.c
+++ b/samples/bpf/test_cgrp2_sock.c
@@ -178,8 +178,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.17.1




^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] samples/bpf: Fix a resource leak
  2024-10-10  1:41 [PATCH] samples/bpf: Fix a resource leak Zhu Jun
@ 2024-10-11  2:20 ` patchwork-bot+netdevbpf
  0 siblings, 0 replies; 2+ messages in thread
From: patchwork-bot+netdevbpf @ 2024-10-11  2:20 UTC (permalink / raw)
  To: Zhu Jun
  Cc: eddyz87, song, yonghong.song, john.fastabend, kpsingh, sdf,
	haoluo, jolsa, bpf, linux-kernel, martin.lau

Hello:

This patch was applied to bpf/bpf-next.git (master)
by Andrii Nakryiko <andrii@kernel.org>:

On Wed,  9 Oct 2024 18:41:26 -0700 you wrote:
> 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>
> ---
>  samples/bpf/test_cgrp2_sock.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)

Here is the summary with links:
  - samples/bpf: Fix a resource leak
    https://git.kernel.org/bpf/bpf-next/c/f3ef53174b23

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-10-11  2:20 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-10  1:41 [PATCH] samples/bpf: Fix a resource leak Zhu Jun
2024-10-11  2:20 ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox