From e48ae1be6382303360ad865941d178695b30d56f Mon Sep 17 00:00:00 2001 From: Vincent Povirk Date: Fri, 9 Apr 2010 11:04:00 -0500 Subject: [PATCH 02/11] windowscodecs: Make IWICStream thread-safe. --- dlls/windowscodecs/stream.c | 8 +++++++- 1 files changed, 7 insertions(+), 1 deletions(-) diff --git a/dlls/windowscodecs/stream.c b/dlls/windowscodecs/stream.c index f3be0c3..24eaf87 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; } -- 1.6.3.3