Commit da5903e7 authored by Nikolay Sivov's avatar Nikolay Sivov Committed by Alexandre Julliard

ole32: Improve locking safety in IMalloc::Free().

parent ed531275
...@@ -254,35 +254,39 @@ static void * WINAPI IMalloc_fnRealloc(IMalloc *iface, void *pv, SIZE_T cb) ...@@ -254,35 +254,39 @@ static void * WINAPI IMalloc_fnRealloc(IMalloc *iface, void *pv, SIZE_T cb)
/****************************************************************************** /******************************************************************************
* IMalloc32_Free [VTABLE] * IMalloc32_Free [VTABLE]
*/ */
static void WINAPI IMalloc_fnFree(IMalloc *iface, void *pv) static void WINAPI IMalloc_fnFree(IMalloc *iface, void *mem)
{ {
BOOL fSpyed = FALSE; BOOL spyed_block = FALSE, spy_active = FALSE;
TRACE("(%p)\n",pv);
if(!pv)
return;
if(Malloc32.pSpy) { TRACE("(%p)\n", mem);
EnterCriticalSection(&IMalloc32_SpyCS);
fSpyed = mallocspy_remove_spyed_memory(pv);
pv = IMallocSpy_PreFree(Malloc32.pSpy, pv, fSpyed);
}
HeapFree(GetProcessHeap(),0,pv); if (!mem)
return;
if(Malloc32.pSpy) { if (Malloc32.pSpy)
IMallocSpy_PostFree(Malloc32.pSpy, fSpyed); {
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 */ HeapFree(GetProcessHeap(), 0, mem);
if(Malloc32.SpyReleasePending && !Malloc32.SpyedAllocationsLeft) {
IMallocSpy_Release(Malloc32.pSpy);
Malloc32.SpyReleasePending = FALSE;
Malloc32.pSpy = NULL;
}
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);
}
} }
/****************************************************************************** /******************************************************************************
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment