Skip to content

Commit 9d0272c

Browse files
theihorAlexei Starovoitov
authored andcommitted
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: 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>
1 parent a1a771b commit 9d0272c

3 files changed

Lines changed: 22 additions & 4 deletions

File tree

tools/testing/selftests/bpf/prog_tests/htab_update.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ static void test_reenter_update(void)
6161

6262
ASSERT_EQ(skel->bss->update_err, -EDEADLK, "no reentrancy");
6363
out:
64+
free(value);
6465
htab_update__destroy(skel);
6566
}
6667

tools/testing/selftests/bpf/prog_tests/test_xsk.c

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2003,9 +2003,17 @@ int testapp_stats_tx_invalid_descs(struct test_spec *test)
20032003

20042004
int testapp_stats_rx_full(struct test_spec *test)
20052005
{
2006-
if (pkt_stream_replace(test, DEFAULT_UMEM_BUFFERS + DEFAULT_UMEM_BUFFERS / 2, MIN_PKT_SIZE))
2006+
struct pkt_stream *tmp;
2007+
2008+
tmp = pkt_stream_generate(DEFAULT_UMEM_BUFFERS + DEFAULT_UMEM_BUFFERS / 2, MIN_PKT_SIZE);
2009+
if (!tmp)
2010+
return TEST_FAILURE;
2011+
test->ifobj_tx->xsk->pkt_stream = tmp;
2012+
2013+
tmp = pkt_stream_generate(DEFAULT_UMEM_BUFFERS, MIN_PKT_SIZE);
2014+
if (!tmp)
20072015
return TEST_FAILURE;
2008-
test->ifobj_rx->xsk->pkt_stream = pkt_stream_generate(DEFAULT_UMEM_BUFFERS, MIN_PKT_SIZE);
2016+
test->ifobj_rx->xsk->pkt_stream = tmp;
20092017

20102018
test->ifobj_rx->xsk->rxqsize = DEFAULT_UMEM_BUFFERS;
20112019
test->ifobj_rx->release_rx = false;
@@ -2015,9 +2023,17 @@ int testapp_stats_rx_full(struct test_spec *test)
20152023

20162024
int testapp_stats_fill_empty(struct test_spec *test)
20172025
{
2018-
if (pkt_stream_replace(test, DEFAULT_UMEM_BUFFERS + DEFAULT_UMEM_BUFFERS / 2, MIN_PKT_SIZE))
2026+
struct pkt_stream *tmp;
2027+
2028+
tmp = pkt_stream_generate(DEFAULT_UMEM_BUFFERS + DEFAULT_UMEM_BUFFERS / 2, MIN_PKT_SIZE);
2029+
if (!tmp)
2030+
return TEST_FAILURE;
2031+
test->ifobj_tx->xsk->pkt_stream = tmp;
2032+
2033+
tmp = pkt_stream_generate(DEFAULT_UMEM_BUFFERS, MIN_PKT_SIZE);
2034+
if (!tmp)
20192035
return TEST_FAILURE;
2020-
test->ifobj_rx->xsk->pkt_stream = pkt_stream_generate(DEFAULT_UMEM_BUFFERS, MIN_PKT_SIZE);
2036+
test->ifobj_rx->xsk->pkt_stream = tmp;
20212037

20222038
test->ifobj_rx->use_fill_ring = false;
20232039
test->ifobj_rx->validation_func = validate_fill_empty;

tools/testing/selftests/bpf/testing_helpers.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ int parse_test_list_file(const char *path,
212212
break;
213213
}
214214

215+
free(buf);
215216
fclose(f);
216217
return err;
217218
}

0 commit comments

Comments
 (0)