samples/bpf: Fix a resource leak

[ Upstream commit f3ef53174b ]

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>
This commit is contained in:
Zhu Jun 2024-10-09 18:41:26 -07:00 committed by Greg Kroah-Hartman
parent 86b66b8091
commit 00c9f6e825

View 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);