From 4a69ec68673889c1bf5444051f63577e945a3a69 Mon Sep 17 00:00:00 2001 From: Yuxuan Shui Date: Fri, 24 Nov 2023 14:36:47 +0000 Subject: [PATCH] amend! mfmediaengine: Be a bit more conservative with locks in engine Shutdown. mfmediaengine: Be a bit more conservative with locks in engine Shutdown. During engine shutdown we acquire engine lock first, then locks of its constituents (e.g. sample grabbers); whereas normally the order is the other way around (e.g. timer callback -> acquire sample grabber lock -> OnProcessSample callback -> engine lock). This is deadlock prone. With this commit, engine lock is released before we shutdown the inner media session. --- dlls/mfmediaengine/main.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/dlls/mfmediaengine/main.c b/dlls/mfmediaengine/main.c index ed9bd75f797..1138a7c9734 100644 --- a/dlls/mfmediaengine/main.c +++ b/dlls/mfmediaengine/main.c @@ -2201,7 +2201,7 @@ static HRESULT WINAPI media_engine_GetVideoAspectRatio(IMFMediaEngineEx *iface, static HRESULT WINAPI media_engine_Shutdown(IMFMediaEngineEx *iface) { struct media_engine *engine = impl_from_IMFMediaEngineEx(iface); - IMFMediaSession *session; + IMFMediaSession *session = NULL; HRESULT hr = S_OK; TRACE("%p.\n", iface); @@ -2218,8 +2218,11 @@ static HRESULT WINAPI media_engine_Shutdown(IMFMediaEngineEx *iface) } LeaveCriticalSection(&engine->cs); - IMFMediaSession_Shutdown(session); - IMFMediaSession_Release(session); + if (SUCCEEDED(hr)) + { + IMFMediaSession_Shutdown(session); + IMFMediaSession_Release(session); + } return hr; }