Commit 9d0272c9 authored by Ihor Solodrai's avatar Ihor Solodrai Committed by Alexei Starovoitov
Browse files

selftests/bpf: Fix memory leaks in tests



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: default avatarEduard Zingerman <eddyz87@gmail.com>
Signed-off-by: default avatarIhor Solodrai <ihor.solodrai@linux.dev>
Link: https://lore.kernel.org/r/20260223190736.649171-11-ihor.solodrai@linux.dev


Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
parent a1a771bd
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -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);
}

+20 −4
Original line number Diff line number Diff line
@@ -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;
+1 −0
Original line number Diff line number Diff line
@@ -212,6 +212,7 @@ int parse_test_list_file(const char *path,
			break;
	}

	free(buf);
	fclose(f);
	return err;
}