mirror of
https://github.com/reactos/reactos.git
synced 2024-12-28 01:55:19 +00:00
-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:
parent
59131bfc00
commit
35bd58021f
1 changed files with 45 additions and 29 deletions
|
@ -536,6 +536,11 @@ GlobalReAlloc(HGLOBAL hMem,
|
|||
{
|
||||
if(ISPOINTER(hMem))
|
||||
{
|
||||
if (!(uFlags & GMEM_MOVEABLE))
|
||||
{
|
||||
heap_flags |= HEAP_REALLOC_IN_PLACE_ONLY;
|
||||
}
|
||||
|
||||
/* reallocate fixed memory */
|
||||
hnew = (HANDLE)RtlReAllocateHeap(GetProcessHeap(), heap_flags, (LPVOID) hMem, dwBytes);
|
||||
}
|
||||
|
@ -543,37 +548,47 @@ GlobalReAlloc(HGLOBAL hMem,
|
|||
{
|
||||
/* reallocate a moveable block */
|
||||
phandle= HANDLE_TO_INTERN(hMem);
|
||||
hnew = hMem;
|
||||
|
||||
if (0 != dwBytes)
|
||||
{
|
||||
hnew = hMem;
|
||||
if(phandle->Pointer)
|
||||
{
|
||||
palloc = RtlReAllocateHeap(GetProcessHeap(), heap_flags,
|
||||
(PVOID)((ULONG_PTR)phandle->Pointer - HANDLE_SIZE),
|
||||
dwBytes + HANDLE_SIZE);
|
||||
if (0 == palloc)
|
||||
{
|
||||
hnew = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
*(PHANDLE)palloc = hMem;
|
||||
phandle->Pointer = (PVOID)((ULONG_PTR)palloc + HANDLE_SIZE);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
if(phandle->Pointer)
|
||||
{
|
||||
|
||||
if (phandle->LockCount && !(uFlags & GMEM_MOVEABLE))
|
||||
{
|
||||
/* Locked memory cant normally move but the MEM_MOVEABLE flag
|
||||
* override this behaviour. But in this case that flag was not passed.
|
||||
*/
|
||||
heap_flags |= HEAP_REALLOC_IN_PLACE_ONLY;
|
||||
}
|
||||
|
||||
palloc = RtlReAllocateHeap(GetProcessHeap(), heap_flags,
|
||||
(PVOID)((ULONG_PTR)phandle->Pointer - HANDLE_SIZE),
|
||||
dwBytes + HANDLE_SIZE);
|
||||
if (0 == palloc)
|
||||
{
|
||||
hnew = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
*(PHANDLE)palloc = hMem;
|
||||
phandle->Pointer = (PVOID)((ULONG_PTR)palloc + HANDLE_SIZE);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
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
|
||||
{
|
||||
|
@ -585,6 +600,7 @@ GlobalReAlloc(HGLOBAL hMem,
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
HeapUnlock(GetProcessHeap());
|
||||
|
||||
return hnew;
|
||||
|
|
Loading…
Reference in a new issue