[QUARTZ][STRMBASE]
authorThomas Faber <thomas.faber@reactos.org>
Tue, 29 Jul 2014 07:49:06 +0000 (07:49 +0000)
committerThomas Faber <thomas.faber@reactos.org>
Tue, 29 Jul 2014 07:49:06 +0000 (07:49 +0000)
- Fix use-after-free on critical sections, which caused test hangs. Also fix some memory leaks. More fixes coming with the next Wine-sync, but this should be enough to get tests working.
ROSTESTS-116

svn path=/trunk/; revision=63757

reactos/dll/directx/wine/quartz/enumfilters.c
reactos/dll/directx/wine/quartz/filesource.c
reactos/dll/directx/wine/quartz/nullrenderer.c
reactos/dll/directx/wine/quartz/parser.c
reactos/include/reactos/wine/strmbase.h
reactos/lib/3rdparty/strmbase/filter.c
reactos/lib/3rdparty/strmbase/renderer.c
reactos/lib/3rdparty/strmbase/transform.c

index c8efcc9..5d13fa0 100644 (file)
@@ -113,6 +113,7 @@ static ULONG WINAPI IEnumFiltersImpl_Release(IEnumFilters * iface)
     if (!refCount)
     {
         IGraphVersion_Release(This->pVersionSource);
     if (!refCount)
     {
         IGraphVersion_Release(This->pVersionSource);
+        CoTaskMemFree(This);
         return 0;
     }
     else
         return 0;
     }
     else
index e63a5f4..46229cc 100644 (file)
@@ -465,7 +465,7 @@ static HRESULT WINAPI AsyncReader_QueryInterface(IBaseFilter * iface, REFIID rii
 static ULONG WINAPI AsyncReader_Release(IBaseFilter * iface)
 {
     AsyncReader *This = impl_from_IBaseFilter(iface);
 static ULONG WINAPI AsyncReader_Release(IBaseFilter * iface)
 {
     AsyncReader *This = impl_from_IBaseFilter(iface);
-    ULONG refCount = BaseFilterImpl_Release(iface);
+    ULONG refCount = InterlockedDecrement(&This->filter.refCount);
     
     TRACE("(%p)->() Release from %d\n", This, refCount + 1);
     
     
     TRACE("(%p)->() Release from %d\n", This, refCount + 1);
     
@@ -485,6 +485,7 @@ static ULONG WINAPI AsyncReader_Release(IBaseFilter * iface)
         CoTaskMemFree(This->pszFileName);
         if (This->pmt)
             FreeMediaType(This->pmt);
         CoTaskMemFree(This->pszFileName);
         if (This->pmt)
             FreeMediaType(This->pmt);
+        BaseFilter_Destroy(&This->filter);
         CoTaskMemFree(This);
         return 0;
     }
         CoTaskMemFree(This);
         return 0;
     }
index b70c81d..432749a 100644 (file)
@@ -108,7 +108,7 @@ static ULONG WINAPI NullRendererInner_AddRef(IUnknown *iface)
 static ULONG WINAPI NullRendererInner_Release(IUnknown *iface)
 {
     NullRendererImpl *This = impl_from_IUnknown(iface);
 static ULONG WINAPI NullRendererInner_Release(IUnknown *iface)
 {
     NullRendererImpl *This = impl_from_IUnknown(iface);
-    ULONG refCount = BaseFilterImpl_Release(&This->renderer.filter.IBaseFilter_iface);
+    ULONG refCount = BaseRendererImpl_Release(&This->renderer.filter.IBaseFilter_iface);
 
     if (!refCount)
     {
 
     if (!refCount)
     {
index 8476838..705c784 100644 (file)
@@ -180,6 +180,7 @@ void Parser_Destroy(ParserImpl *This)
     }
 
     CoTaskMemFree(This->ppPins);
     }
 
     CoTaskMemFree(This->ppPins);
+    BaseFilter_Destroy(&This->filter);
 
     TRACE("Destroying parser\n");
     CoTaskMemFree(This);
 
     TRACE("Destroying parser\n");
     CoTaskMemFree(This);
@@ -188,7 +189,7 @@ void Parser_Destroy(ParserImpl *This)
 ULONG WINAPI Parser_Release(IBaseFilter * iface)
 {
     ParserImpl *This = impl_from_IBaseFilter(iface);
 ULONG WINAPI Parser_Release(IBaseFilter * iface)
 {
     ParserImpl *This = impl_from_IBaseFilter(iface);
-    ULONG refCount = BaseFilterImpl_Release(iface);
+    ULONG refCount = InterlockedDecrement(&This->filter.refCount);
 
     TRACE("(%p)->() Release from %d\n", This, refCount + 1);
 
 
     TRACE("(%p)->() Release from %d\n", This, refCount + 1);
 
index 9727fb4..1370198 100644 (file)
@@ -194,6 +194,7 @@ LONG WINAPI BaseFilterImpl_GetPinVersion(BaseFilter* This);
 VOID WINAPI BaseFilterImpl_IncrementPinVersion(BaseFilter* This);
 
 HRESULT WINAPI BaseFilter_Init(BaseFilter * This, const IBaseFilterVtbl *Vtbl, const CLSID *pClsid, DWORD_PTR DebugInfo, const BaseFilterFuncTable* pBaseFuncsTable);
 VOID WINAPI BaseFilterImpl_IncrementPinVersion(BaseFilter* This);
 
 HRESULT WINAPI BaseFilter_Init(BaseFilter * This, const IBaseFilterVtbl *Vtbl, const CLSID *pClsid, DWORD_PTR DebugInfo, const BaseFilterFuncTable* pBaseFuncsTable);
+HRESULT WINAPI BaseFilter_Destroy(BaseFilter * This);
 
 /* Enums */
 HRESULT WINAPI EnumMediaTypes_Construct(BasePin *iface, BasePin_GetMediaType enumFunc, BasePin_GetMediaTypeVersion versionFunc, IEnumMediaTypes ** ppEnum);
 
 /* Enums */
 HRESULT WINAPI EnumMediaTypes_Construct(BasePin *iface, BasePin_GetMediaType enumFunc, BasePin_GetMediaTypeVersion versionFunc, IEnumMediaTypes ** ppEnum);
index 10d9460..09d3b5b 100644 (file)
@@ -60,14 +60,7 @@ ULONG WINAPI BaseFilterImpl_Release(IBaseFilter * iface)
     TRACE("(%p)->() Release from %d\n", This, refCount + 1);
 
     if (!refCount)
     TRACE("(%p)->() Release from %d\n", This, refCount + 1);
 
     if (!refCount)
-    {
-        if (This->pClock)
-            IReferenceClock_Release(This->pClock);
-
-        This->IBaseFilter_iface.lpVtbl = NULL;
-        This->csFilter.DebugInfo->Spare[0] = 0;
-        DeleteCriticalSection(&This->csFilter);
-    }
+        BaseFilter_Destroy(This);
 
     return refCount;
 }
 
     return refCount;
 }
@@ -209,3 +202,15 @@ HRESULT WINAPI BaseFilter_Init(BaseFilter * This, const IBaseFilterVtbl *Vtbl, c
 
     return S_OK;
 }
 
     return S_OK;
 }
+
+HRESULT WINAPI BaseFilter_Destroy(BaseFilter * This)
+{
+    if (This->pClock)
+        IReferenceClock_Release(This->pClock);
+
+    This->IBaseFilter_iface.lpVtbl = NULL;
+    This->csFilter.DebugInfo->Spare[0] = 0;
+    DeleteCriticalSection(&This->csFilter);
+
+    return S_OK;
+}
index 433bcba..cf2f318 100644 (file)
@@ -284,7 +284,7 @@ HRESULT WINAPI BaseRendererImpl_QueryInterface(IBaseFilter* iface, REFIID riid,
 ULONG WINAPI BaseRendererImpl_Release(IBaseFilter* iface)
 {
     BaseRenderer *This = impl_from_IBaseFilter(iface);
 ULONG WINAPI BaseRendererImpl_Release(IBaseFilter* iface)
 {
     BaseRenderer *This = impl_from_IBaseFilter(iface);
-    ULONG refCount = BaseFilterImpl_Release(iface);
+    ULONG refCount = InterlockedDecrement(&This->filter.refCount);
 
     if (!refCount)
     {
 
     if (!refCount)
     {
@@ -309,6 +309,7 @@ ULONG WINAPI BaseRendererImpl_Release(IBaseFilter* iface)
         CloseHandle(This->ThreadSignal);
         CloseHandle(This->RenderEvent);
         QualityControlImpl_Destroy(This->qcimpl);
         CloseHandle(This->ThreadSignal);
         CloseHandle(This->RenderEvent);
         QualityControlImpl_Destroy(This->qcimpl);
+        BaseFilter_Destroy(&This->filter);
     }
     return refCount;
 }
     }
     return refCount;
 }
index 8f5815a..dc59bb9 100644 (file)
@@ -295,7 +295,7 @@ HRESULT WINAPI TransformFilterImpl_QueryInterface(IBaseFilter * iface, REFIID ri
 ULONG WINAPI TransformFilterImpl_Release(IBaseFilter * iface)
 {
     TransformFilter *This = impl_from_IBaseFilter(iface);
 ULONG WINAPI TransformFilterImpl_Release(IBaseFilter * iface)
 {
     TransformFilter *This = impl_from_IBaseFilter(iface);
-    ULONG refCount = BaseFilterImpl_Release(iface);
+    ULONG refCount = InterlockedDecrement(&This->filter.refCount);
 
     TRACE("(%p/%p)->() Release from %d\n", This, iface, refCount + 1);
 
 
     TRACE("(%p/%p)->() Release from %d\n", This, iface, refCount + 1);
 
@@ -325,6 +325,7 @@ ULONG WINAPI TransformFilterImpl_Release(IBaseFilter * iface)
         FreeMediaType(&This->pmt);
         QualityControlImpl_Destroy(This->qcimpl);
         IUnknown_Release(This->seekthru_unk);
         FreeMediaType(&This->pmt);
         QualityControlImpl_Destroy(This->qcimpl);
         IUnknown_Release(This->seekthru_unk);
+        BaseFilter_Destroy(&This->filter);
         CoTaskMemFree(This);
 
         return 0;
         CoTaskMemFree(This);
 
         return 0;