]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
selftests/bpf: test_xsk: fix memory leak in testapp_stats_rx_dropped()
authorBastien Curutchet (eBPF Foundation) <bastien.curutchet@bootlin.com>
Fri, 31 Oct 2025 08:04:40 +0000 (09:04 +0100)
committerAlexei Starovoitov <ast@kernel.org>
Fri, 31 Oct 2025 16:24:38 +0000 (09:24 -0700)
testapp_stats_rx_dropped() generates pkt_stream twice. The last
generated is released by pkt_stream_restore_default() at the end of the
test but we lose the pointer of the first pkt_stream.

Release the 'middle' pkt_stream when it's getting replaced to prevent
memory leaks.

Reviewed-by: Maciej Fijalkowski <maciej.fijalkowski@intel.com>
Signed-off-by: Bastien Curutchet (eBPF Foundation) <bastien.curutchet@bootlin.com>
Link: https://lore.kernel.org/r/20251031-xsk-v7-4-39fe486593a3@bootlin.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
tools/testing/selftests/bpf/test_xsk.c

index 8d7c38eb32ca3537cb019f120c3350ebd9f8c6bc..eb18288ea1e4aa1c9337d16333b7174ecaed0999 100644 (file)
@@ -536,6 +536,13 @@ static void pkt_stream_receive_half(struct test_spec *test)
        struct pkt_stream *pkt_stream = test->ifobj_tx->xsk->pkt_stream;
        u32 i;
 
+       if (test->ifobj_rx->xsk->pkt_stream != test->rx_pkt_stream_default)
+               /* Packet stream has already been replaced so we have to release this one.
+                * The newly created one will be freed by the restore_default() at the
+                * end of the test
+                */
+               pkt_stream_delete(test->ifobj_rx->xsk->pkt_stream);
+
        test->ifobj_rx->xsk->pkt_stream = pkt_stream_generate(pkt_stream->nb_pkts,
                                                              pkt_stream->pkts[0].len);
        pkt_stream = test->ifobj_rx->xsk->pkt_stream;