Skip to content

Commit fbdf26d

Browse files
Zhu Jungregkh
authored andcommitted
samples/bpf: Fix a resource leak
[ Upstream commit f3ef531 ] 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>
1 parent 8945c33 commit fbdf26d

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

samples/bpf/test_cgrp2_sock.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,10 @@ static int show_sockopts(int family)
178178
return 1;
179179
}
180180

181-
if (get_bind_to_device(sd, name, sizeof(name)) < 0)
181+
if (get_bind_to_device(sd, name, sizeof(name)) < 0) {
182+
close(sd);
182183
return 1;
184+
}
183185

184186
mark = get_somark(sd);
185187
prio = get_priority(sd);

0 commit comments

Comments
 (0)