From 1dc4c3e4293747e35cf4b71af613d89ddcda12e7 Mon Sep 17 00:00:00 2001 From: Li_Xin6 Date: Tue, 5 Nov 2024 15:52:21 +0800 Subject: [PATCH] [CP] Fix memleak in xe gpucontext 1. gpucontext memory leaked due to re-create context call Clear go into GpuContextSpecificNextXe::Clear missed actual clean up. remove Clear() due to it is a empty function. 2. add nullptr check to avoid lock of null mutex. --- .../os/mos_gpucontext_specific_next.cpp | 32 +++++++++++-------- .../os/xe/mos_gpucontext_specific_next_xe.cpp | 7 ---- .../os/xe/mos_gpucontext_specific_next_xe.h | 2 -- 3 files changed, 18 insertions(+), 23 deletions(-) diff --git a/media_softlet/linux/common/os/mos_gpucontext_specific_next.cpp b/media_softlet/linux/common/os/mos_gpucontext_specific_next.cpp index b2c976f2a9..98fbe93309 100644 --- a/media_softlet/linux/common/os/mos_gpucontext_specific_next.cpp +++ b/media_softlet/linux/common/os/mos_gpucontext_specific_next.cpp @@ -671,25 +671,29 @@ void GpuContextSpecificNext::Clear() } MOS_FreeMemAndSetNull(m_statusBufferResource); - MosUtilities::MosLockMutex(m_cmdBufPoolMutex); - - if (m_cmdBufMgr) + if(m_cmdBufPoolMutex) { - for (auto& curCommandBuffer : m_cmdBufPool) + MosUtilities::MosLockMutex(m_cmdBufPoolMutex); + + if (m_cmdBufMgr) { - auto curCommandBufferSpecific = static_cast(curCommandBuffer); - if (curCommandBufferSpecific == nullptr) - continue; - curCommandBufferSpecific->waitReady(); // wait ready and return to comamnd buffer manager. - m_cmdBufMgr->ReleaseCmdBuf(curCommandBuffer); + for (auto& curCommandBuffer : m_cmdBufPool) + { + auto curCommandBufferSpecific = static_cast(curCommandBuffer); + if (curCommandBufferSpecific == nullptr) + continue; + curCommandBufferSpecific->waitReady(); // wait ready and return to comamnd buffer manager. + m_cmdBufMgr->ReleaseCmdBuf(curCommandBuffer); + } } - } - m_cmdBufPool.clear(); + m_cmdBufPool.clear(); + + MosUtilities::MosUnlockMutex(m_cmdBufPoolMutex); + MosUtilities::MosDestroyMutex(m_cmdBufPoolMutex); + m_cmdBufPoolMutex = nullptr; + } - MosUtilities::MosUnlockMutex(m_cmdBufPoolMutex); - MosUtilities::MosDestroyMutex(m_cmdBufPoolMutex); - m_cmdBufPoolMutex = nullptr; MOS_SafeFreeMemory(m_commandBuffer); m_commandBuffer = nullptr; MOS_SafeFreeMemory(m_allocationList); diff --git a/media_softlet/linux/common/os/xe/mos_gpucontext_specific_next_xe.cpp b/media_softlet/linux/common/os/xe/mos_gpucontext_specific_next_xe.cpp index 14435e35e4..29b31671bf 100644 --- a/media_softlet/linux/common/os/xe/mos_gpucontext_specific_next_xe.cpp +++ b/media_softlet/linux/common/os/xe/mos_gpucontext_specific_next_xe.cpp @@ -42,8 +42,6 @@ static pthread_mutex_t command_dump_mutex = PTHREAD_MUTEX_INITIALIZER; GpuContextSpecificNextXe::~GpuContextSpecificNextXe() { MOS_OS_FUNCTION_ENTER; - - Clear(); } MOS_STATUS GpuContextSpecificNextXe::Init3DCtx(PMOS_CONTEXT osParameters, @@ -250,11 +248,6 @@ MOS_STATUS GpuContextSpecificNextXe::InitBltCtx(PMOS_CONTEXT osParameters, return eStatus; } -void GpuContextSpecificNextXe::Clear() -{ - MOS_OS_FUNCTION_ENTER; -} - MOS_STATUS GpuContextSpecificNextXe::PatchCommandBuffer( MOS_STREAM_HANDLE streamState, PMOS_COMMAND_BUFFER cmdBuffer) diff --git a/media_softlet/linux/common/os/xe/mos_gpucontext_specific_next_xe.h b/media_softlet/linux/common/os/xe/mos_gpucontext_specific_next_xe.h index 18aa4d63cc..3b9c9bb4b7 100644 --- a/media_softlet/linux/common/os/xe/mos_gpucontext_specific_next_xe.h +++ b/media_softlet/linux/common/os/xe/mos_gpucontext_specific_next_xe.h @@ -50,8 +50,6 @@ class GpuContextSpecificNextXe : public GpuContextSpecificNext //! ~GpuContextSpecificNextXe(); - virtual void Clear(void) override; - virtual MOS_STATUS SubmitCommandBuffer( MOS_STREAM_HANDLE streamState, PMOS_COMMAND_BUFFER cmdBuffer,