-dont return NULL when realloc to 0 bytes (fixes one kernel32_winetest heap test)

-only allow realloc to new position if GMEM_MOVEABLE is passed (fixed mem)
-only allow realloc to new position if GMEM_MOVEABLE is passed OR mem is not locked (moveable mem)

svn path=/trunk/; revision=18528
This commit is contained in:
Gunnar Dalsnes 2005-10-17 20:11:21 +00:00
parent 59131bfc00
commit 35bd58021f

View file

@ -536,6 +536,11 @@ GlobalReAlloc(HGLOBAL hMem,
{ {
if(ISPOINTER(hMem)) if(ISPOINTER(hMem))
{ {
if (!(uFlags & GMEM_MOVEABLE))
{
heap_flags |= HEAP_REALLOC_IN_PLACE_ONLY;
}
/* reallocate fixed memory */ /* reallocate fixed memory */
hnew = (HANDLE)RtlReAllocateHeap(GetProcessHeap(), heap_flags, (LPVOID) hMem, dwBytes); hnew = (HANDLE)RtlReAllocateHeap(GetProcessHeap(), heap_flags, (LPVOID) hMem, dwBytes);
} }
@ -543,37 +548,47 @@ GlobalReAlloc(HGLOBAL hMem,
{ {
/* reallocate a moveable block */ /* reallocate a moveable block */
phandle= HANDLE_TO_INTERN(hMem); phandle= HANDLE_TO_INTERN(hMem);
hnew = hMem;
if (0 != dwBytes) if (0 != dwBytes)
{ {
hnew = hMem; if(phandle->Pointer)
if(phandle->Pointer) {
{
palloc = RtlReAllocateHeap(GetProcessHeap(), heap_flags, if (phandle->LockCount && !(uFlags & GMEM_MOVEABLE))
(PVOID)((ULONG_PTR)phandle->Pointer - HANDLE_SIZE), {
dwBytes + HANDLE_SIZE); /* Locked memory cant normally move but the MEM_MOVEABLE flag
if (0 == palloc) * override this behaviour. But in this case that flag was not passed.
{ */
hnew = 0; heap_flags |= HEAP_REALLOC_IN_PLACE_ONLY;
} }
else
{ palloc = RtlReAllocateHeap(GetProcessHeap(), heap_flags,
*(PHANDLE)palloc = hMem; (PVOID)((ULONG_PTR)phandle->Pointer - HANDLE_SIZE),
phandle->Pointer = (PVOID)((ULONG_PTR)palloc + HANDLE_SIZE); dwBytes + HANDLE_SIZE);
} if (0 == palloc)
} {
else hnew = 0;
{ }
palloc = RtlAllocateHeap(GetProcessHeap(), heap_flags, dwBytes + HANDLE_SIZE); else
if (0 == palloc) {
{ *(PHANDLE)palloc = hMem;
hnew = 0; phandle->Pointer = (PVOID)((ULONG_PTR)palloc + HANDLE_SIZE);
} }
else }
{ else
*(PHANDLE)palloc = hMem; {
phandle->Pointer = (PVOID)((ULONG_PTR)palloc + HANDLE_SIZE); palloc = RtlAllocateHeap(GetProcessHeap(), heap_flags, dwBytes + HANDLE_SIZE);
} if (0 == palloc)
} {
hnew = 0;
}
else
{
*(PHANDLE)palloc = hMem;
phandle->Pointer = (PVOID)((ULONG_PTR)palloc + HANDLE_SIZE);
}
}
} }
else else
{ {
@ -585,6 +600,7 @@ GlobalReAlloc(HGLOBAL hMem,
} }
} }
} }
HeapUnlock(GetProcessHeap()); HeapUnlock(GetProcessHeap());
return hnew; return hnew;