Dan Kegel : ntdll: Add missing RtlReAllocateHeap Valgrind hook, add tests.

Alexandre Julliard julliard at winehq.org
Mon Apr 27 08:04:04 CDT 2009


Module: wine
Branch: master
Commit: 3e6d0789d0bc2070850156836f0ef13d80b15c8e
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=3e6d0789d0bc2070850156836f0ef13d80b15c8e

Author: Dan Kegel <dank at kegel.com>
Date:   Thu Apr 23 06:47:20 2009 -0700

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 deletions(-)

diff --git a/dlls/kernel32/tests/heap.c b/dlls/kernel32/tests/heap.c
index 39efde9..a674e07 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 255a688..4abd35e 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) &&




More information about the wine-cvs mailing list