diff --git a/dlls/kernel32/heap.c b/dlls/kernel32/heap.c index fd6414a34ec..e68420a55bb 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 67dc8b6df40..fefd3e79561 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);