From 1bb6c221f6b1570177dfdd2f73f126e4edf2f4a6 Mon Sep 17 00:00:00 2001 From: Niklas Eiling Date: Sat, 10 Feb 2024 16:21:03 +0100 Subject: [PATCH] ips/dma: fix memory leak in libxil code by explicitly calling free on CyclicBd Signed-off-by: Niklas Eiling --- fpga/lib/ips/dma.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/fpga/lib/ips/dma.cpp b/fpga/lib/ips/dma.cpp index 27d0a7a25..a5852d4b4 100644 --- a/fpga/lib/ips/dma.cpp +++ b/fpga/lib/ips/dma.cpp @@ -201,6 +201,18 @@ Dma::~Dma() { // Unmap memory in our ownership, MemoryBlock gets deleted and removed from // graph by this destructor as well. if (hasScatterGather()) { + // Fix memory leak in upstream Xilinx code + auto txRingPtr = XAxiDma_GetTxRing(&xDma); + auto rxRingPtr = XAxiDma_GetRxRing(&xDma); + if (txRingPtr) { + free(txRingPtr->CyclicBd); + txRingPtr->CyclicBd = nullptr; + } + if (rxRingPtr) { + free(rxRingPtr->CyclicBd); + rxRingPtr->CyclicBd = nullptr; + } + // unampe SG memory Blocks if (sgRingTx) { card->unmapMemoryBlock(*sgRingTx); }