samples/bpf: Fix a resource leak

BugLink: https://bugs.launchpad.net/bugs/2102118

[ 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>
Signed-off-by: Koichiro Den <koichiro.den@canonical.com>
Signed-off-by: Stefan Bader <stefan.bader@canonical.com>
This commit is contained in:
Zhu Jun
2025-03-12 22:51:00 +09:00
committed by Stefan Bader
parent f2ea7026a0
commit 58419d6bee
+3 -1
View File
@@ -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);