/****************************************************************************** * IMalloc32_Free [VTABLE] */ static VOID WINAPI IMalloc_fnFree(LPMALLOC iface,LPVOID pv) { BOOL fSpyed = 0; TRACE("(%p)\n",pv); if(Malloc32.pSpy) { EnterCriticalSection(&IMalloc32_SpyCS); fSpyed = RemoveMemoryLocation(pv); pv = IMallocSpy_PreFree(Malloc32.pSpy, pv, fSpyed); } HeapFree(GetProcessHeap(),0,pv); if(Malloc32.pSpy) { IMallocSpy_PostFree(Malloc32.pSpy, fSpyed); /* check if can release the spy */ if(Malloc32.SpyReleasePending && !Malloc32.SpyedAllocationsLeft) { IMallocSpy_Release(Malloc32.pSpy); Malloc32.SpyReleasePending = FALSE; Malloc32.pSpy = NULL; } LeaveCriticalSection(&IMalloc32_SpyCS); } }
/****************************************************************************** * IMalloc32_Realloc [VTABLE] */ static LPVOID WINAPI IMalloc_fnRealloc(LPMALLOC iface,LPVOID pv,DWORD cb) { LPVOID pNewMemory; TRACE("(%p,%d)\n",pv,cb); if(Malloc32.pSpy) { LPVOID pRealMemory; BOOL fSpyed; EnterCriticalSection(&IMalloc32_SpyCS); fSpyed = RemoveMemoryLocation(pv); cb = IMallocSpy_PreRealloc(Malloc32.pSpy, pv, cb, &pRealMemory, fSpyed); /* check if can release the spy */ if(Malloc32.SpyReleasePending && !Malloc32.SpyedAllocationsLeft) { IMallocSpy_Release(Malloc32.pSpy); Malloc32.SpyReleasePending = FALSE; Malloc32.pSpy = NULL; LeaveCriticalSection(&IMalloc32_SpyCS); } if (0==cb) { /* PreRealloc can force Realloc to fail */ if (Malloc32.pSpy) LeaveCriticalSection(&IMalloc32_SpyCS); return NULL; } pv = pRealMemory; } if (!pv) pNewMemory = HeapAlloc(GetProcessHeap(),0,cb); else if (cb) pNewMemory = HeapReAlloc(GetProcessHeap(),0,pv,cb); else { HeapFree(GetProcessHeap(),0,pv); pNewMemory = NULL; } if(Malloc32.pSpy) { pNewMemory = IMallocSpy_PostRealloc(Malloc32.pSpy, pNewMemory, TRUE); if (pNewMemory) AddMemoryLocation(pNewMemory); LeaveCriticalSection(&IMalloc32_SpyCS); } TRACE("--(%p)\n",pNewMemory); return pNewMemory; }