Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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

authored by

Malaya Kumar Rout and committed by
Andrii Nakryiko
be2fea9c 5709be4c

+4 -3
+1 -2
tools/testing/selftests/bpf/benchs/bench_htab_mem.c
··· 279 279 } 280 280 281 281 got = read(fd, buf, sizeof(buf) - 1); 282 + close(fd); 282 283 if (got <= 0) { 283 284 *value = 0; 284 285 return; ··· 287 286 buf[got] = 0; 288 287 289 288 *value = strtoull(buf, NULL, 0); 290 - 291 - close(fd); 292 289 } 293 290 294 291 static void htab_mem_measure(struct bench_res *res)
+3 -1
tools/testing/selftests/bpf/prog_tests/sk_assign.c
··· 37 37 tc = popen("tc -V", "r"); 38 38 if (CHECK_FAIL(!tc)) 39 39 return false; 40 - if (CHECK_FAIL(!fgets(tc_version, sizeof(tc_version), tc))) 40 + if (CHECK_FAIL(!fgets(tc_version, sizeof(tc_version), tc))) { 41 + pclose(tc); 41 42 return false; 43 + } 42 44 if (strstr(tc_version, ", libbpf ")) 43 45 prog = "test_sk_assign_libbpf.bpf.o"; 44 46 else