diff options
author | Zhu Jun <[email protected]> | 2024-10-09 18:41:26 -0700 |
---|---|---|
committer | Andrii Nakryiko <[email protected]> | 2024-10-10 19:13:47 -0700 |
commit | f3ef53174b23246fe9bc2bbc2542f3a3856fa1e2 (patch) | |
tree | bee2c9df68dd9459c1f4081ca3d28fb0d56491dd | |
parent | c6ca31981b545ad3081007b6aa88b6aab1b0cece (diff) |
samples/bpf: Fix a resource leak
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 <[email protected]>
Signed-off-by: Andrii Nakryiko <[email protected]>
Link: https://lore.kernel.org/bpf/[email protected]
-rw-r--r-- | samples/bpf/test_cgrp2_sock.c | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/samples/bpf/test_cgrp2_sock.c b/samples/bpf/test_cgrp2_sock.c index a0811df888f4..8ca2a445ffa1 100644 --- a/samples/bpf/test_cgrp2_sock.c +++ b/samples/bpf/test_cgrp2_sock.c @@ -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); |