Commit 3e6d0789 authored by Dan Kegel's avatar Dan Kegel Committed by Alexandre Julliard

ntdll: Add missing RtlReAllocateHeap Valgrind hook, add tests.

parent 52b1de84
......@@ -34,7 +34,30 @@ static SIZE_T resize_9x(SIZE_T size)
return max(dwSizeAligned, 12); /* at least 12 bytes */
}
START_TEST(heap)
static void test_sized_HeapAlloc(int nbytes)
{
int success;
char *buf = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, nbytes);
ok(buf != NULL, "allocate failed");
ok(buf[0] == 0, "buffer not zeroed");
success = HeapFree(GetProcessHeap(), 0, buf);
ok(success, "free failed");
}
static void test_sized_HeapReAlloc(int nbytes1, int nbytes2)
{
int success;
char *buf = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, nbytes1);
ok(buf != NULL, "allocate failed");
ok(buf[0] == 0, "buffer not zeroed");
buf = HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, buf, nbytes2);
ok(buf != NULL, "reallocate failed");
ok(buf[nbytes2-1] == 0, "buffer not zeroed");
success = HeapFree(GetProcessHeap(), 0, buf);
ok(success, "free failed");
}
static void test_heap(void)
{
LPVOID mem;
LPVOID msecond;
......@@ -338,3 +361,16 @@ START_TEST(heap)
GlobalFree(gbl);
}
START_TEST(heap)
{
test_heap();
/* Test both short and very long blocks */
test_sized_HeapAlloc(1);
test_sized_HeapAlloc(1 << 20);
test_sized_HeapReAlloc(1, 100);
test_sized_HeapReAlloc(1, (1 << 20));
test_sized_HeapReAlloc((1 << 20), (2 << 20));
test_sized_HeapReAlloc((1 << 20), 1);
}
......@@ -1535,6 +1535,8 @@ PVOID WINAPI RtlReAllocateHeap( HANDLE heap, ULONG flags, PVOID ptr, SIZE_T size
{
if (!find_large_block( heapPtr, ptr )) goto error;
if (!(ret = realloc_large_block( heapPtr, flags, ptr, size ))) goto oom;
notify_free( ptr );
notify_alloc( ret, size, flags & HEAP_ZERO_MEMORY );
goto done;
}
if ((char *)pArena < (char *)subheap->base + subheap->headerSize) goto error;
......@@ -1551,7 +1553,9 @@ PVOID WINAPI RtlReAllocateHeap( HANDLE heap, ULONG flags, PVOID ptr, SIZE_T size
if (rounded_size >= HEAP_MIN_LARGE_BLOCK_SIZE && (flags & HEAP_GROWABLE))
{
if (!(ret = allocate_large_block( heapPtr, flags, size ))) goto oom;
notify_alloc( ret, size, flags & HEAP_ZERO_MEMORY );
memcpy( ret, pArena + 1, oldActualSize );
/* FIXME: free old memory here! */
goto done;
}
if ((pNext < (char *)subheap->base + subheap->size) &&
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment