Skip to content

Commit

Permalink
[Media Common] [VP] fix double free issue in FreeGpuStatusBuf
Browse files Browse the repository at this point in the history
use mutex to protect the gpucontext free
  • Loading branch information
pengwan1 authored and intel-mediadev committed Oct 17, 2024
1 parent b7dff1f commit 62769c9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
13 changes: 12 additions & 1 deletion media_softlet/agnostic/common/os/mos_gpucontextmgr_next.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, Intel Corporation
* Copyright (c) 2019-2024, Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
Expand Down Expand Up @@ -55,6 +55,12 @@ GpuContextMgrNext::~GpuContextMgrNext()
MosUtilities::MosDestroyMutex(m_gpuContextArrayMutex);
m_gpuContextArrayMutex = nullptr;
}

if (m_gpuContextDeleteArrayMutex)
{
MosUtilities::MosDestroyMutex(m_gpuContextDeleteArrayMutex);
m_gpuContextDeleteArrayMutex = nullptr;
}
}

MOS_STATUS GpuContextMgrNext::Initialize()
Expand All @@ -63,6 +69,9 @@ MOS_STATUS GpuContextMgrNext::Initialize()
m_gpuContextArrayMutex = MosUtilities::MosCreateMutex();
MOS_OS_CHK_NULL_RETURN(m_gpuContextArrayMutex);

m_gpuContextDeleteArrayMutex = MosUtilities::MosCreateMutex();
MOS_OS_CHK_NULL_RETURN(m_gpuContextDeleteArrayMutex);

MosUtilities::MosLockMutex(m_gpuContextArrayMutex);
m_gpuContextMap.clear();
MosUtilities::MosUnlockMutex(m_gpuContextArrayMutex);
Expand Down Expand Up @@ -266,7 +275,9 @@ void GpuContextMgrNext::DestroyGpuContext(GpuContextNext *gpuContext)

if (found)
{
MosUtilities::MosLockMutex(m_gpuContextDeleteArrayMutex);
MOS_Delete(gpuContext); // delete gpu context.
MosUtilities::MosUnlockMutex(m_gpuContextDeleteArrayMutex);
}
else
{
Expand Down
7 changes: 5 additions & 2 deletions media_softlet/agnostic/common/os/mos_gpucontextmgr_next.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, Intel Corporation
* Copyright (c) 2019-2024, Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
Expand Down Expand Up @@ -169,7 +169,10 @@ class GpuContextMgrNext

//! \brief Gpu context array mutex
PMOS_MUTEX m_gpuContextArrayMutex = nullptr;


//! \brief Gpu context array mutex for delete
PMOS_MUTEX m_gpuContextDeleteArrayMutex = nullptr;

//! \brief Gpu context count
uint32_t m_gpuContextCount = 0;
uint32_t m_gpuContextHanleForNonCycledCase = 0;
Expand Down

0 comments on commit 62769c9

Please sign in to comment.