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()

Signed-off-by: Bastien Curutchet (eBPF Foundation) 
<bastien.curutc...@bootlin.com>
---
 tools/testing/selftests/bpf/test_xsk.c | 23 ++++++++++++++++++++++-
 1 file changed, 22 insertions(+), 1 deletion(-)

diff --git a/tools/testing/selftests/bpf/test_xsk.c 
b/tools/testing/selftests/bpf/test_xsk.c
index 
eb18288ea1e4aa1c9337d16333b7174ecaed0999..d7cb2821469c62abd0d532821e836336a2177eb5
 100644
--- a/tools/testing/selftests/bpf/test_xsk.c
+++ b/tools/testing/selftests/bpf/test_xsk.c
@@ -570,6 +570,22 @@ static void pkt_stream_even_odd_sequence(struct test_spec 
*test)
        }
 }
 
+static void release_even_odd_sequence(struct test_spec *test)
+{
+       struct pkt_stream *later_free_tx = test->ifobj_tx->xsk->pkt_stream;
+       struct pkt_stream *later_free_rx = test->ifobj_rx->xsk->pkt_stream;
+       int i;
+
+       for (i = 0; i < test->nb_sockets; i++) {
+               /* later_free_{rx/tx} will be freed by restore_default() */
+               if (test->ifobj_tx->xsk_arr[i].pkt_stream != later_free_tx)
+                       
pkt_stream_delete(test->ifobj_tx->xsk_arr[i].pkt_stream);
+               if (test->ifobj_rx->xsk_arr[i].pkt_stream != later_free_rx)
+                       
pkt_stream_delete(test->ifobj_rx->xsk_arr[i].pkt_stream);
+       }
+
+}
+
 static u64 pkt_get_addr(struct pkt *pkt, struct xsk_umem_info *umem)
 {
        if (!pkt->valid)
@@ -2043,6 +2059,7 @@ int testapp_xdp_shared_umem(struct test_spec *test)
 {
        struct xsk_xdp_progs *skel_rx = test->ifobj_rx->xdp_progs;
        struct xsk_xdp_progs *skel_tx = test->ifobj_tx->xdp_progs;
+       int ret;
 
        test->total_steps = 1;
        test->nb_sockets = 2;
@@ -2053,7 +2070,11 @@ int testapp_xdp_shared_umem(struct test_spec *test)
 
        pkt_stream_even_odd_sequence(test);
 
-       return testapp_validate_traffic(test);
+       ret = testapp_validate_traffic(test);
+
+       release_even_odd_sequence(test);
+
+       return ret;
 }
 
 int testapp_poll_txq_tmout(struct test_spec *test)

-- 
2.51.0


Reply via email to