IMallocSpy cannot cause an allocation failure when cb == 0.

This commit is contained in:
Mike Hearn 2003-07-22 01:01:06 +00:00 committed by Alexandre Julliard
parent 72d8aa5ec2
commit cb7db104dd
1 changed files with 8 additions and 6 deletions

View File

@ -144,16 +144,18 @@ static LPVOID WINAPI IMalloc_fnAlloc(LPMALLOC iface, DWORD cb) {
TRACE("(%ld)\n",cb); TRACE("(%ld)\n",cb);
if(Malloc32.pSpy) { if(Malloc32.pSpy) {
DWORD preAllocResult;
EnterCriticalSection(&IMalloc32_SpyCS); EnterCriticalSection(&IMalloc32_SpyCS);
cb = IMallocSpy_PreAlloc(Malloc32.pSpy, cb); preAllocResult = IMallocSpy_PreAlloc(Malloc32.pSpy, cb);
if (0==cb) { if ((cb != 0) && (preAllocResult == 0)) {
/* PreAlloc can force Alloc to fail */ /* PreAlloc can force Alloc to fail, but not if cb == 0 */
LeaveCriticalSection(&IMalloc32_SpyCS); TRACE("returning null\n");
LeaveCriticalSection(&IMalloc32_SpyCS);
return NULL; return NULL;
} }
} }
addr = HeapAlloc(GetProcessHeap(),0,cb); addr = HeapAlloc(GetProcessHeap(),0,cb);
if(Malloc32.pSpy) { if(Malloc32.pSpy) {