Skip to content

Commit d66e49f

Browse files
bastien-curutchetAlexei Starovoitov
authored andcommitted
selftests/bpf: test_xsk: fix memory leak in testapp_stats_rx_dropped()
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 <[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 cadc0c1 commit d66e49f

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

tools/testing/selftests/bpf/test_xsk.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,13 @@ static void pkt_stream_receive_half(struct test_spec *test)
536536
struct pkt_stream *pkt_stream = test->ifobj_tx->xsk->pkt_stream;
537537
u32 i;
538538

539+
if (test->ifobj_rx->xsk->pkt_stream != test->rx_pkt_stream_default)
540+
/* Packet stream has already been replaced so we have to release this one.
541+
* The newly created one will be freed by the restore_default() at the
542+
* end of the test
543+
*/
544+
pkt_stream_delete(test->ifobj_rx->xsk->pkt_stream);
545+
539546
test->ifobj_rx->xsk->pkt_stream = pkt_stream_generate(pkt_stream->nb_pkts,
540547
pkt_stream->pkts[0].len);
541548
pkt_stream = test->ifobj_rx->xsk->pkt_stream;

0 commit comments

Comments
 (0)