Nikolay Sivov : kernel32: Fix return code from LocalUnlock for pointer passed to it.

Alexandre Julliard julliard at winehq.org
Mon May 10 11:59:10 CDT 2010


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

Author: Nikolay Sivov <nsivov at codeweavers.com>
Date:   Sun May  9 02:21:50 2010 +0400

kernel32: Fix return code from LocalUnlock for pointer passed to it.

---

 dlls/kernel32/heap.c       |    9 ++++++++-
 dlls/kernel32/tests/heap.c |   28 ++++++++++++++++++++++++----
 2 files changed, 32 insertions(+), 5 deletions(-)

diff --git a/dlls/kernel32/heap.c b/dlls/kernel32/heap.c
index 4d36a1d..bdfa00b 100644
--- a/dlls/kernel32/heap.c
+++ b/dlls/kernel32/heap.c
@@ -1116,7 +1116,14 @@ SIZE_T WINAPI LocalSize(
  */
 BOOL WINAPI LocalUnlock(
               HLOCAL handle /* [in] Handle of memory object */
-) {
+)
+{
+    if (ISPOINTER( handle ))
+    {
+        SetLastError( ERROR_NOT_LOCKED );
+        return FALSE;
+    }
+
     return GlobalUnlock( handle );
 }
 
diff --git a/dlls/kernel32/tests/heap.c b/dlls/kernel32/tests/heap.c
index f7e985d..98c99d7 100644
--- a/dlls/kernel32/tests/heap.c
+++ b/dlls/kernel32/tests/heap.c
@@ -249,14 +249,27 @@ static void test_heap(void)
 
     res = GlobalUnlock(gbl);
     ok(res == 1 ||
-       res == 0, /* win9x */
+       broken(res == 0), /* win9x */
        "Expected 1 or 0, got %d\n", res);
 
     res = GlobalUnlock(gbl);
     ok(res == 1 ||
-       res == 0, /* win9x */
+       broken(res == 0), /* win9x */
        "Expected 1 or 0, got %d\n", res);
 
+    GlobalFree(gbl);
+
+    gbl = GlobalAlloc(GMEM_FIXED, 100);
+
+    SetLastError(0xdeadbeef);
+    res = GlobalUnlock(gbl);
+    ok(res == 1 ||
+       broken(res == 0), /* win9x */
+       "Expected 1 or 0, got %d\n", res);
+    ok(GetLastError() == 0xdeadbeef, "got %d\n", GetLastError());
+
+    GlobalFree(gbl);
+
     /* GlobalSize on an invalid handle */
     if (sizeof(void *) != 8)  /* crashes on 64-bit Vista */
     {
@@ -268,8 +281,6 @@ static void test_heap(void)
            "Expected ERROR_INVALID_HANDLE or ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
     }
 
-    GlobalFree(gbl);
-
     /* ####################################### */
     /* Local*() functions */
     gbl = LocalAlloc(LMEM_MOVEABLE, 0);
@@ -371,6 +382,15 @@ static void test_heap(void)
         "returned %d with %d (expected '0' with ERROR_INVALID_HANDLE)\n",
         res, GetLastError());
 
+    /* trying to unlock pointer from LocalAlloc */
+    gbl = LocalAlloc(LMEM_FIXED, 100);
+    SetLastError(0xdeadbeef);
+    res = LocalUnlock(gbl);
+    ok(res == 0, "Expected 0, got %d\n", res);
+    ok(GetLastError() == ERROR_NOT_LOCKED ||
+       broken(GetLastError() == 0xdeadbeef) /* win9x */, "got %d\n", GetLastError());
+    LocalFree(gbl);
+
     /* trying to lock empty memory should give an error */
     gbl = GlobalAlloc(GMEM_MOVEABLE|GMEM_ZEROINIT,0);
     ok(gbl != NULL, "returned NULL\n");




More information about the wine-cvs mailing list