Skip to content

Commit bea4f03

Browse files
bastien-curutchetAlexei Starovoitov
authored andcommitted
selftests/bpf: test_xsk: fix memory leak in testapp_xdp_shared_umem()
testapp_xdp_shared_umem() generates pkt_stream on each xsk from xsk_arr, where normally xsk_arr[0] gets pkt_streams and xsk_arr[1] have them NULLed. At the end of the test pkt_stream_restore_default() only releases xsk_arr[0] which leads to memory leaks. Release the missing pkt_stream at the end of testapp_xdp_shared_umem() Reviewed-by: Maciej Fijalkowski <[email protected]> Signed-off-by: Bastien Curutchet (eBPF Foundation) <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alexei Starovoitov <[email protected]>
1 parent d66e49f commit bea4f03

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

tools/testing/selftests/bpf/test_xsk.c

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,22 @@ static void pkt_stream_even_odd_sequence(struct test_spec *test)
570570
}
571571
}
572572

573+
static void release_even_odd_sequence(struct test_spec *test)
574+
{
575+
struct pkt_stream *later_free_tx = test->ifobj_tx->xsk->pkt_stream;
576+
struct pkt_stream *later_free_rx = test->ifobj_rx->xsk->pkt_stream;
577+
int i;
578+
579+
for (i = 0; i < test->nb_sockets; i++) {
580+
/* later_free_{rx/tx} will be freed by restore_default() */
581+
if (test->ifobj_tx->xsk_arr[i].pkt_stream != later_free_tx)
582+
pkt_stream_delete(test->ifobj_tx->xsk_arr[i].pkt_stream);
583+
if (test->ifobj_rx->xsk_arr[i].pkt_stream != later_free_rx)
584+
pkt_stream_delete(test->ifobj_rx->xsk_arr[i].pkt_stream);
585+
}
586+
587+
}
588+
573589
static u64 pkt_get_addr(struct pkt *pkt, struct xsk_umem_info *umem)
574590
{
575591
if (!pkt->valid)
@@ -2043,6 +2059,7 @@ int testapp_xdp_shared_umem(struct test_spec *test)
20432059
{
20442060
struct xsk_xdp_progs *skel_rx = test->ifobj_rx->xdp_progs;
20452061
struct xsk_xdp_progs *skel_tx = test->ifobj_tx->xdp_progs;
2062+
int ret;
20462063

20472064
test->total_steps = 1;
20482065
test->nb_sockets = 2;
@@ -2053,7 +2070,11 @@ int testapp_xdp_shared_umem(struct test_spec *test)
20532070

20542071
pkt_stream_even_odd_sequence(test);
20552072

2056-
return testapp_validate_traffic(test);
2073+
ret = testapp_validate_traffic(test);
2074+
2075+
release_even_odd_sequence(test);
2076+
2077+
return ret;
20572078
}
20582079

20592080
int testapp_poll_txq_tmout(struct test_spec *test)

0 commit comments

Comments
 (0)