Daniel Lehman : kernel32: Change error return from GlobalFree.

Alexandre Julliard julliard at winehq.org
Mon Feb 5 16:48:25 CST 2018


Module: wine
Branch: master
Commit: fe09e2dba66095f1494946226c911a2acc65c9c6
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=fe09e2dba66095f1494946226c911a2acc65c9c6

Author: Daniel Lehman <dlehman at esri.com>
Date:   Tue Jan 30 12:18:02 2018 -0800

kernel32: Change error return from GlobalFree.

Signed-off-by: Daniel Lehman <dlehman at esri.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/kernel32/heap.c       |  4 ++--
 dlls/kernel32/tests/heap.c | 16 ++++++++++++++--
 2 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/dlls/kernel32/heap.c b/dlls/kernel32/heap.c
index fd6414a..e68420a 100644
--- a/dlls/kernel32/heap.c
+++ b/dlls/kernel32/heap.c
@@ -784,8 +784,8 @@ HGLOBAL WINAPI GlobalFree(HGLOBAL hmem)
     }
     __EXCEPT_PAGE_FAULT
     {
-        ERR("(%p): Page fault occurred ! Caused by bug ?\n", hmem);
-        SetLastError( ERROR_INVALID_PARAMETER );
+        ERR("invalid handle %p\n", hmem);
+        SetLastError(ERROR_INVALID_HANDLE);
         hreturned = hmem;
     }
     __ENDTRY
diff --git a/dlls/kernel32/tests/heap.c b/dlls/kernel32/tests/heap.c
index 67dc8b6..fefd3e7 100644
--- a/dlls/kernel32/tests/heap.c
+++ b/dlls/kernel32/tests/heap.c
@@ -208,7 +208,7 @@ static void test_heap(void)
         ((GetLastError() == ERROR_NOT_LOCKED) || (GetLastError() == MAGIC_DEAD)),
         "returned %d with %d (expected '0' with: ERROR_NOT_LOCKED or "
         "MAGIC_DEAD)\n", res, GetLastError());
- 
+
     GlobalFree(gbl);
     /* invalid handles are caught in windows: */
     SetLastError(MAGIC_DEAD);
@@ -217,6 +217,18 @@ static void test_heap(void)
         "returned %p with 0x%08x (expected %p with ERROR_INVALID_HANDLE)\n",
         hsecond, GetLastError(), gbl);
     SetLastError(MAGIC_DEAD);
+    hsecond = GlobalFree(LongToHandle(0xdeadbeef)); /* bogus handle */
+    ok( (hsecond == LongToHandle(0xdeadbeef)) && (GetLastError() == ERROR_INVALID_HANDLE),
+        "returned %p with 0x%08x (expected %p with ERROR_INVALID_HANDLE)\n",
+        hsecond, GetLastError(), LongToHandle(0xdeadbeef));
+    SetLastError(MAGIC_DEAD);
+    hsecond = GlobalFree(LongToHandle(0xdeadbee0)); /* bogus pointer */
+    ok( (hsecond == LongToHandle(0xdeadbee0)) &&
+        ((GetLastError() == ERROR_INVALID_HANDLE) || broken(GetLastError() == ERROR_NOACCESS) /* wvista+ */),
+        "returned %p with 0x%08x (expected %p with ERROR_NOACCESS)\n",
+        hsecond, GetLastError(), LongToHandle(0xdeadbee0));
+
+    SetLastError(MAGIC_DEAD);
     flags = GlobalFlags(gbl);
     ok( (flags == GMEM_INVALID_HANDLE) && (GetLastError() == ERROR_INVALID_HANDLE),
         "returned 0x%04x with 0x%08x (expected GMEM_INVALID_HANDLE with "
@@ -250,7 +262,7 @@ static void test_heap(void)
     ok(mem == NULL, "Expected NULL, got %p\n", mem);
 
     /* invalid free */
-    if (sizeof(void *) != 8)  /* crashes on 64-bit Vista */
+    if (sizeof(void *) != 8)  /* crashes on 64-bit */
     {
         SetLastError(MAGIC_DEAD);
         mem = GlobalFree(gbl);




More information about the wine-cvs mailing list