]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
samples/bpf: Fix a resource leak
authorZhu Jun <zhujun2@cmss.chinamobile.com>
Thu, 10 Oct 2024 01:41:26 +0000 (18:41 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 14 Dec 2024 18:51:36 +0000 (19:51 +0100)
[ 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

index b0811da5a00f3af5f950e8400c011045004504e3..3f56519a1ccd761955e16ac6cfd08d90cfd6643f 100644 (file)
@@ -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);