From a6bf1287bae2c29908821de2fef7dc043d1153dc Mon Sep 17 00:00:00 2001 From: Vincent Povirk Date: Fri, 9 Apr 2010 11:04:00 -0500 Subject: [PATCH] windowscodecs: Make IWICStream thread-safe. --- dlls/windowscodecs/stream.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/dlls/windowscodecs/stream.c b/dlls/windowscodecs/stream.c index f3be0c319ee..24eaf87feed 100644 --- a/dlls/windowscodecs/stream.c +++ b/dlls/windowscodecs/stream.c @@ -477,7 +477,13 @@ static HRESULT WINAPI IWICStreamImpl_InitializeFromMemory(IWICStream *iface, InitializeCriticalSection(&pObject->lock); pObject->lock.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": StreamOnMemory.lock"); - This->pStream = (IStream*)pObject; + if (InterlockedCompareExchangePointer((void**)&This->pStream, pObject, NULL)) + { + /* Some other thread set the stream first. */ + IStream_Release((IStream*)pObject); + return WINCODEC_ERR_WRONGSTATE; + } + return S_OK; } -- 2.11.4.GIT