Robert Shearman : kernel32: Fix GlobalReAlloc for size = 0.

Alexandre Julliard julliard at wine.codeweavers.com
Thu Jan 12 06:43:20 CST 2006


Module: wine
Branch: refs/heads/master
Commit: 9cc41d278ff1d0bebe034ca64d82388751e4aeb6
URL:    http://source.winehq.org/git/?p=wine.git;a=commit;h=9cc41d278ff1d0bebe034ca64d82388751e4aeb6

Author: Robert Shearman <rob at codeweavers.com>
Date:   Thu Jan 12 11:55:25 2006 +0100

kernel32: Fix GlobalReAlloc for size = 0.
GlobalReAlloc should return NULL if the requested size is 0, the block
is moveable and it is locked, but otherwise it should return the
original memory block.

---

 dlls/kernel/heap.c       |   12 +++++++++---
 dlls/kernel/tests/heap.c |   14 ++++----------
 2 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/dlls/kernel/heap.c b/dlls/kernel/heap.c
index 6c0b913..19d4b5b 100644
--- a/dlls/kernel/heap.c
+++ b/dlls/kernel/heap.c
@@ -657,11 +657,17 @@ HGLOBAL WINAPI GlobalReAlloc(
          }
          else
          {
-            if(pintern->Pointer)
+            if (pintern->LockCount == 0)
             {
-               HeapFree(GetProcessHeap(), 0, (char *) pintern->Pointer-HGLOBAL_STORAGE);
-               pintern->Pointer=NULL;
+                if(pintern->Pointer)
+                {
+                    HeapFree(GetProcessHeap(), 0, (char *) pintern->Pointer-HGLOBAL_STORAGE);
+                    pintern->Pointer = NULL;
+                }
+                hnew = hmem;
             }
+            else
+                WARN("not freeing memory associated with locked handle\n");
          }
       }
    }
diff --git a/dlls/kernel/tests/heap.c b/dlls/kernel/tests/heap.c
index 27a51cf..a6284a0 100644
--- a/dlls/kernel/tests/heap.c
+++ b/dlls/kernel/tests/heap.c
@@ -63,11 +63,8 @@ START_TEST(heap)
     size = GlobalSize(gbl);
     ok(size >= 10 && size <= 16, "Memory not resized to size 10, instead size=%ld\n", size);
 
-    todo_wine
-    { 
-        gbl = GlobalReAlloc(gbl, 0, GMEM_MOVEABLE);
-        ok(gbl != NULL, "GlobalReAlloc should not fail on size 0\n");
-    }
+    gbl = GlobalReAlloc(gbl, 0, GMEM_MOVEABLE);
+    ok(gbl != NULL, "GlobalReAlloc should not fail on size 0\n");
 
     size = GlobalSize(gbl);
     ok(size == 0, "Memory not resized to size 0, instead size=%ld\n", size);
@@ -87,11 +84,8 @@ START_TEST(heap)
     size = LocalSize(gbl);
     ok(size >= 10 && size <= 16, "Memory not resized to size 10, instead size=%ld\n", size);
 
-    todo_wine
-    {
-        gbl = LocalReAlloc(gbl, 0, LMEM_MOVEABLE);
-        ok(gbl != NULL, "LocalReAlloc should not fail on size 0\n");
-    }
+    gbl = LocalReAlloc(gbl, 0, LMEM_MOVEABLE);
+    ok(gbl != NULL, "LocalReAlloc should not fail on size 0\n");
 
     size = LocalSize(gbl);
     ok(size == 0, "Memory not resized to size 0, instead size=%ld\n", size);




More information about the wine-cvs mailing list