]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph-client.git/commitdiff
selftests/bpf: Fix memory leaks in tests
authorIhor Solodrai <ihor.solodrai@linux.dev>
Mon, 23 Feb 2026 19:07:26 +0000 (11:07 -0800)
committerAlexei Starovoitov <ast@kernel.org>
Tue, 24 Feb 2026 16:19:49 +0000 (08:19 -0800)
Fix trivial memory leaks detected by userspace ASAN:
  - htab_update: free value buffer in test_reenter_update cleanup
  - test_xsk: inline pkt_stream_replace() in testapp_stats_rx_full()
    and testapp_stats_fill_empty()
  - testing_helpers: free buffer allocated by getline() in
    parse_test_list_file

Acked-by: Eduard Zingerman <eddyz87@gmail.com>
Signed-off-by: Ihor Solodrai <ihor.solodrai@linux.dev>
Link: https://lore.kernel.org/r/20260223190736.649171-11-ihor.solodrai@linux.dev
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
tools/testing/selftests/bpf/prog_tests/htab_update.c
tools/testing/selftests/bpf/prog_tests/test_xsk.c
tools/testing/selftests/bpf/testing_helpers.c

index d0b405eb296627cab47620fe5436c5156028a3ad..ea1a6766fbe9872886abb532b62e96f94f66fba0 100644 (file)
@@ -61,6 +61,7 @@ static void test_reenter_update(void)
 
        ASSERT_EQ(skel->bss->update_err, -EDEADLK, "no reentrancy");
 out:
+       free(value);
        htab_update__destroy(skel);
 }
 
index bab4a31621c75108d70ceb68549b8343b4a01b71..7e38ec6e656b97ac878b20b64441069eb4d531f2 100644 (file)
@@ -2003,9 +2003,17 @@ int testapp_stats_tx_invalid_descs(struct test_spec *test)
 
 int testapp_stats_rx_full(struct test_spec *test)
 {
-       if (pkt_stream_replace(test, DEFAULT_UMEM_BUFFERS + DEFAULT_UMEM_BUFFERS / 2, MIN_PKT_SIZE))
+       struct pkt_stream *tmp;
+
+       tmp = pkt_stream_generate(DEFAULT_UMEM_BUFFERS + DEFAULT_UMEM_BUFFERS / 2, MIN_PKT_SIZE);
+       if (!tmp)
+               return TEST_FAILURE;
+       test->ifobj_tx->xsk->pkt_stream = tmp;
+
+       tmp = pkt_stream_generate(DEFAULT_UMEM_BUFFERS, MIN_PKT_SIZE);
+       if (!tmp)
                return TEST_FAILURE;
-       test->ifobj_rx->xsk->pkt_stream = pkt_stream_generate(DEFAULT_UMEM_BUFFERS, MIN_PKT_SIZE);
+       test->ifobj_rx->xsk->pkt_stream = tmp;
 
        test->ifobj_rx->xsk->rxqsize = DEFAULT_UMEM_BUFFERS;
        test->ifobj_rx->release_rx = false;
@@ -2015,9 +2023,17 @@ int testapp_stats_rx_full(struct test_spec *test)
 
 int testapp_stats_fill_empty(struct test_spec *test)
 {
-       if (pkt_stream_replace(test, DEFAULT_UMEM_BUFFERS + DEFAULT_UMEM_BUFFERS / 2, MIN_PKT_SIZE))
+       struct pkt_stream *tmp;
+
+       tmp = pkt_stream_generate(DEFAULT_UMEM_BUFFERS + DEFAULT_UMEM_BUFFERS / 2, MIN_PKT_SIZE);
+       if (!tmp)
+               return TEST_FAILURE;
+       test->ifobj_tx->xsk->pkt_stream = tmp;
+
+       tmp = pkt_stream_generate(DEFAULT_UMEM_BUFFERS, MIN_PKT_SIZE);
+       if (!tmp)
                return TEST_FAILURE;
-       test->ifobj_rx->xsk->pkt_stream = pkt_stream_generate(DEFAULT_UMEM_BUFFERS, MIN_PKT_SIZE);
+       test->ifobj_rx->xsk->pkt_stream = tmp;
 
        test->ifobj_rx->use_fill_ring = false;
        test->ifobj_rx->validation_func = validate_fill_empty;
index 16eb37e5bad697ef65a3e4c949e84a30efd43e69..66af0d13751acebde0274c1ea5efa9bd6a40cd5e 100644 (file)
@@ -212,6 +212,7 @@ int parse_test_list_file(const char *path,
                        break;
        }
 
+       free(buf);
        fclose(f);
        return err;
 }