Skip to content

Commit

Permalink
samples/bpf: Fix a resource leak
Browse files Browse the repository at this point in the history
[ 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>
  • Loading branch information
Zhu Jun authored and gregkh committed Dec 14, 2024
1 parent 8945c33 commit fbdf26d
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion samples/bpf/test_cgrp2_sock.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit fbdf26d

Please sign in to comment.