From 3e6d0789d0bc2070850156836f0ef13d80b15c8e Mon Sep 17 00:00:00 2001 From: Dan Kegel Date: Thu, 23 Apr 2009 06:47:20 -0700 Subject: [PATCH] ntdll: Add missing RtlReAllocateHeap Valgrind hook, add tests. --- dlls/kernel32/tests/heap.c | 38 +++++++++++++++++++++++++++++++++++++- dlls/ntdll/heap.c | 4 ++++ 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/dlls/kernel32/tests/heap.c b/dlls/kernel32/tests/heap.c index 39efde9811d..a674e074965 100644 --- a/dlls/kernel32/tests/heap.c +++ b/dlls/kernel32/tests/heap.c @@ -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); +} diff --git a/dlls/ntdll/heap.c b/dlls/ntdll/heap.c index 255a688bd4f..4abd35e11e4 100644 --- a/dlls/ntdll/heap.c +++ b/dlls/ntdll/heap.c @@ -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) && -- 2.11.4.GIT