From d34ab182e41e9672c79c301a59881771c40fb95a Mon Sep 17 00:00:00 2001 From: Niklas Eiling Date: Tue, 19 Dec 2023 11:12:14 +0100 Subject: [PATCH] fix unmapped ring buffers in dma.cpp leading to segfault Signed-off-by: Niklas Eiling --- fpga/lib/ips/dma.cpp | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/fpga/lib/ips/dma.cpp b/fpga/lib/ips/dma.cpp index 1da604901..e8f8494e4 100644 --- a/fpga/lib/ips/dma.cpp +++ b/fpga/lib/ips/dma.cpp @@ -193,15 +193,18 @@ bool Dma::reset() return false; } -Dma::~Dma() -{ - // Unmap memory in our ownership, MemoryBlock gets deleted and removed from - // graph by this destructor as well. - if (hasScatterGather()) { - card->unmapMemoryBlock(*sgRingTx); - card->unmapMemoryBlock(*sgRingRx); - } - Dma::reset(); +Dma::~Dma() { + // Unmap memory in our ownership, MemoryBlock gets deleted and removed from + // graph by this destructor as well. + if (hasScatterGather()) { + if (sgRingTx) { + card->unmapMemoryBlock(*sgRingTx); + } + if (sgRingRx) { + card->unmapMemoryBlock(*sgRingRx); + } + } + Dma::reset(); } bool Dma::memcpy(const MemoryBlock &src, const MemoryBlock &dst, size_t len)