kernel32: Reset stdio handles when they are closed.

This commit is contained in:
Alexandre Julliard 2010-05-26 22:10:52 +02:00
parent 5d4a7433a6
commit 775e5f7b3e
2 changed files with 16 additions and 4 deletions

View File

@ -2713,10 +2713,12 @@ BOOL WINAPI CloseHandle( HANDLE handle )
NTSTATUS status; NTSTATUS status;
/* stdio handles need special treatment */ /* stdio handles need special treatment */
if ((handle == (HANDLE)STD_INPUT_HANDLE) || if (handle == (HANDLE)STD_INPUT_HANDLE)
(handle == (HANDLE)STD_OUTPUT_HANDLE) || handle = InterlockedExchangePointer( &NtCurrentTeb()->Peb->ProcessParameters->hStdInput, 0 );
(handle == (HANDLE)STD_ERROR_HANDLE)) else if (handle == (HANDLE)STD_OUTPUT_HANDLE)
handle = GetStdHandle( HandleToULong(handle) ); handle = InterlockedExchangePointer( &NtCurrentTeb()->Peb->ProcessParameters->hStdOutput, 0 );
else if (handle == (HANDLE)STD_ERROR_HANDLE)
handle = InterlockedExchangePointer( &NtCurrentTeb()->Peb->ProcessParameters->hStdError, 0 );
if (is_console_handle(handle)) if (is_console_handle(handle))
return CloseConsoleHandle(handle); return CloseConsoleHandle(handle);

View File

@ -1742,6 +1742,7 @@ static void test_ProcessName(void)
static void test_Handles(void) static void test_Handles(void)
{ {
HANDLE handle = GetCurrentProcess(); HANDLE handle = GetCurrentProcess();
HANDLE h2;
BOOL ret; BOOL ret;
DWORD code; DWORD code;
@ -1769,6 +1770,15 @@ static void test_Handles(void)
ok( !ret, "GetExitCodeProcess succeeded for %p\n", handle ); ok( !ret, "GetExitCodeProcess succeeded for %p\n", handle );
ok( GetLastError() == ERROR_INVALID_HANDLE, "wrong error %u\n", GetLastError() ); ok( GetLastError() == ERROR_INVALID_HANDLE, "wrong error %u\n", GetLastError() );
#endif #endif
handle = GetStdHandle( STD_ERROR_HANDLE );
ok( handle != 0, "handle %p\n", handle );
CloseHandle( (HANDLE)STD_ERROR_HANDLE );
h2 = GetStdHandle( STD_ERROR_HANDLE );
ok( h2 == 0 ||
broken( h2 == handle) || /* nt4, w2k */
broken( h2 == INVALID_HANDLE_VALUE), /* win9x */
"wrong handle %p/%p\n", h2, handle );
} }
static void test_SystemInfo(void) static void test_SystemInfo(void)