Commit 0597e659 authored by Nikolay Sivov's avatar Nikolay Sivov Committed by Alexandre Julliard

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

parent 9494cdc5
...@@ -1116,7 +1116,14 @@ SIZE_T WINAPI LocalSize( ...@@ -1116,7 +1116,14 @@ SIZE_T WINAPI LocalSize(
*/ */
BOOL WINAPI LocalUnlock( BOOL WINAPI LocalUnlock(
HLOCAL handle /* [in] Handle of memory object */ HLOCAL handle /* [in] Handle of memory object */
) { )
{
if (ISPOINTER( handle ))
{
SetLastError( ERROR_NOT_LOCKED );
return FALSE;
}
return GlobalUnlock( handle ); return GlobalUnlock( handle );
} }
......
...@@ -249,14 +249,27 @@ static void test_heap(void) ...@@ -249,14 +249,27 @@ static void test_heap(void)
res = GlobalUnlock(gbl); res = GlobalUnlock(gbl);
ok(res == 1 || ok(res == 1 ||
res == 0, /* win9x */ broken(res == 0), /* win9x */
"Expected 1 or 0, got %d\n", res); "Expected 1 or 0, got %d\n", res);
res = GlobalUnlock(gbl); res = GlobalUnlock(gbl);
ok(res == 1 || ok(res == 1 ||
res == 0, /* win9x */ broken(res == 0), /* win9x */
"Expected 1 or 0, got %d\n", res); "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 */ /* GlobalSize on an invalid handle */
if (sizeof(void *) != 8) /* crashes on 64-bit Vista */ if (sizeof(void *) != 8) /* crashes on 64-bit Vista */
{ {
...@@ -268,8 +281,6 @@ static void test_heap(void) ...@@ -268,8 +281,6 @@ static void test_heap(void)
"Expected ERROR_INVALID_HANDLE or ERROR_INVALID_PARAMETER, got %d\n", GetLastError()); "Expected ERROR_INVALID_HANDLE or ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
} }
GlobalFree(gbl);
/* ####################################### */ /* ####################################### */
/* Local*() functions */ /* Local*() functions */
gbl = LocalAlloc(LMEM_MOVEABLE, 0); gbl = LocalAlloc(LMEM_MOVEABLE, 0);
...@@ -371,6 +382,15 @@ static void test_heap(void) ...@@ -371,6 +382,15 @@ static void test_heap(void)
"returned %d with %d (expected '0' with ERROR_INVALID_HANDLE)\n", "returned %d with %d (expected '0' with ERROR_INVALID_HANDLE)\n",
res, GetLastError()); 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 */ /* trying to lock empty memory should give an error */
gbl = GlobalAlloc(GMEM_MOVEABLE|GMEM_ZEROINIT,0); gbl = GlobalAlloc(GMEM_MOVEABLE|GMEM_ZEROINIT,0);
ok(gbl != NULL, "returned NULL\n"); ok(gbl != NULL, "returned NULL\n");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment