-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)
Modified: trunk/reactos/lib/kernel32/mem/global.c
_____
Modified: trunk/reactos/lib/kernel32/mem/global.c
--- trunk/reactos/lib/kernel32/mem/global.c 2005-10-17 19:29:51 UTC
(rev 18527)
+++ trunk/reactos/lib/kernel32/mem/global.c 2005-10-17 20:11:21 UTC
(rev 18528)
@@ -536,6 +536,11 @@
{
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 @@
{
/* 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 @@
}
}
}
+
HeapUnlock(GetProcessHeap());
return hnew;
Show replies by date