Alexandre Julliard : kernel32: Reset stdio handles when they are closed.

Alexandre Julliard julliard at winehq.org
Thu May 27 10:46:38 CDT 2010


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

Author: Alexandre Julliard <julliard at winehq.org>
Date:   Wed May 26 22:10:52 2010 +0200

kernel32: Reset stdio handles when they are closed.

---

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

diff --git a/dlls/kernel32/process.c b/dlls/kernel32/process.c
index b71a390..af06392 100644
--- a/dlls/kernel32/process.c
+++ b/dlls/kernel32/process.c
@@ -2713,10 +2713,12 @@ BOOL WINAPI CloseHandle( HANDLE handle )
     NTSTATUS status;
 
     /* stdio handles need special treatment */
-    if ((handle == (HANDLE)STD_INPUT_HANDLE) ||
-        (handle == (HANDLE)STD_OUTPUT_HANDLE) ||
-        (handle == (HANDLE)STD_ERROR_HANDLE))
-        handle = GetStdHandle( HandleToULong(handle) );
+    if (handle == (HANDLE)STD_INPUT_HANDLE)
+        handle = InterlockedExchangePointer( &NtCurrentTeb()->Peb->ProcessParameters->hStdInput, 0 );
+    else if (handle == (HANDLE)STD_OUTPUT_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))
         return CloseConsoleHandle(handle);
diff --git a/dlls/kernel32/tests/process.c b/dlls/kernel32/tests/process.c
index 846c338..d66d9f6 100644
--- a/dlls/kernel32/tests/process.c
+++ b/dlls/kernel32/tests/process.c
@@ -1742,6 +1742,7 @@ static void test_ProcessName(void)
 static void test_Handles(void)
 {
     HANDLE handle = GetCurrentProcess();
+    HANDLE h2;
     BOOL ret;
     DWORD code;
 
@@ -1769,6 +1770,15 @@ static void test_Handles(void)
     ok( !ret, "GetExitCodeProcess succeeded for %p\n", handle );
     ok( GetLastError() == ERROR_INVALID_HANDLE, "wrong error %u\n", GetLastError() );
 #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)




More information about the wine-cvs mailing list