Skip to content

Commit

Permalink
[CP] Fix memleak in xe gpucontext
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
lixin5x authored and intel-mediadev committed Nov 5, 2024
1 parent 2aba298 commit 1dc4c3e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 23 deletions.
32 changes: 18 additions & 14 deletions media_softlet/linux/common/os/mos_gpucontext_specific_next.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<CommandBufferSpecificNext *>(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<CommandBufferSpecificNext *>(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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 1dc4c3e

Please sign in to comment.