From 62769c9253316e610097f6b6f359ca75b2864691 Mon Sep 17 00:00:00 2001 From: Wang_PengX Date: Thu, 17 Oct 2024 14:41:12 +0800 Subject: [PATCH] [Media Common] [VP] fix double free issue in FreeGpuStatusBuf use mutex to protect the gpucontext free --- .../agnostic/common/os/mos_gpucontextmgr_next.cpp | 13 ++++++++++++- .../agnostic/common/os/mos_gpucontextmgr_next.h | 7 +++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/media_softlet/agnostic/common/os/mos_gpucontextmgr_next.cpp b/media_softlet/agnostic/common/os/mos_gpucontextmgr_next.cpp index f403ae52c97..3762e9525dc 100644 --- a/media_softlet/agnostic/common/os/mos_gpucontextmgr_next.cpp +++ b/media_softlet/agnostic/common/os/mos_gpucontextmgr_next.cpp @@ -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"), @@ -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() @@ -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); @@ -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 { diff --git a/media_softlet/agnostic/common/os/mos_gpucontextmgr_next.h b/media_softlet/agnostic/common/os/mos_gpucontextmgr_next.h index 65bb3a8c6db..fbd1ab65793 100644 --- a/media_softlet/agnostic/common/os/mos_gpucontextmgr_next.h +++ b/media_softlet/agnostic/common/os/mos_gpucontextmgr_next.h @@ -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"), @@ -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;