selftests/bpf: Close the file descriptor to avoid resource leaks
authorMalaya Kumar Rout <malayarout91@gmail.com>
Mon, 21 Apr 2025 17:44:05 +0000 (23:14 +0530)
committerAndrii Nakryiko <andrii@kernel.org>
Tue, 22 Apr 2025 21:29:58 +0000 (14:29 -0700)
commitbe2fea9c07d40a0a897580166e3d43c53ef3b75b
treed5303c09958bff7fa3f58e8696c4b4392913e295
parent5709be4c35ba760b001733939e20069de033a697
selftests/bpf: Close the file descriptor to avoid resource leaks

Static analysis found an issue in bench_htab_mem.c and sk_assign.c

cppcheck output before this patch:
tools/testing/selftests/bpf/benchs/bench_htab_mem.c:284:3: error: Resource leak: fd [resourceLeak]
tools/testing/selftests/bpf/prog_tests/sk_assign.c:41:3: error: Resource leak: tc [resourceLeak]

cppcheck output after this patch:
No resource leaks found

Fix the issue by closing the file descriptors fd and tc.

Signed-off-by: Malaya Kumar Rout <malayarout91@gmail.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20250421174405.26080-1-malayarout91@gmail.com
tools/testing/selftests/bpf/benchs/bench_htab_mem.c
tools/testing/selftests/bpf/prog_tests/sk_assign.c