Signed-off-by: Nikolay Sivov nsivov@codeweavers.com --- dlls/ole32/ifs.c | 48 ++++++++++++++++++++++++++---------------------- 1 file changed, 26 insertions(+), 22 deletions(-)
diff --git a/dlls/ole32/ifs.c b/dlls/ole32/ifs.c index dfced20de2..f1dae0c956 100644 --- a/dlls/ole32/ifs.c +++ b/dlls/ole32/ifs.c @@ -254,35 +254,39 @@ static void * WINAPI IMalloc_fnRealloc(IMalloc *iface, void *pv, SIZE_T cb) /****************************************************************************** * IMalloc32_Free [VTABLE] */ -static void WINAPI IMalloc_fnFree(IMalloc *iface, void *pv) +static void WINAPI IMalloc_fnFree(IMalloc *iface, void *mem) { - BOOL fSpyed = FALSE; - - TRACE("(%p)\n",pv); - - if(!pv) - return; + BOOL spyed_block = FALSE, spy_active = FALSE;
- if(Malloc32.pSpy) { - EnterCriticalSection(&IMalloc32_SpyCS); - fSpyed = mallocspy_remove_spyed_memory(pv); - pv = IMallocSpy_PreFree(Malloc32.pSpy, pv, fSpyed); - } + TRACE("(%p)\n", mem);
- HeapFree(GetProcessHeap(),0,pv); + if (!mem) + return;
- if(Malloc32.pSpy) { - IMallocSpy_PostFree(Malloc32.pSpy, fSpyed); + if (Malloc32.pSpy) + { + EnterCriticalSection(&IMalloc32_SpyCS); + spyed_block = mallocspy_remove_spyed_memory(mem); + spy_active = TRUE; + mem = IMallocSpy_PreFree(Malloc32.pSpy, mem, spyed_block); + }
- /* check if can release the spy */ - if(Malloc32.SpyReleasePending && !Malloc32.SpyedAllocationsLeft) { - IMallocSpy_Release(Malloc32.pSpy); - Malloc32.SpyReleasePending = FALSE; - Malloc32.pSpy = NULL; - } + HeapFree(GetProcessHeap(), 0, mem);
- LeaveCriticalSection(&IMalloc32_SpyCS); + if (spy_active) + { + IMallocSpy_PostFree(Malloc32.pSpy, spyed_block); + + /* check if can release the spy */ + if (Malloc32.SpyReleasePending && !Malloc32.SpyedAllocationsLeft) + { + IMallocSpy_Release(Malloc32.pSpy); + Malloc32.SpyReleasePending = FALSE; + Malloc32.pSpy = NULL; } + + LeaveCriticalSection(&IMalloc32_SpyCS); + } }
/******************************************************************************