kernelbase: Close PEB ConsoleHandle in FreeConsole.

Signed-off-by: Jacek Caban <jacek@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Jacek Caban 2020-08-13 16:00:27 +02:00 committed by Alexandre Julliard
parent 701b0139d1
commit ccaaf6957f
2 changed files with 15 additions and 0 deletions

View File

@ -3592,9 +3592,15 @@ static void test_FreeConsole(void)
HANDLE handle;
BOOL ret;
todo_wine
ok(RtlGetCurrentPeb()->ProcessParameters->ConsoleHandle != NULL, "ConsoleHandle is NULL\n");
ret = FreeConsole();
ok(ret, "FreeConsole failed: %u\n", GetLastError());
ok(RtlGetCurrentPeb()->ProcessParameters->ConsoleHandle == NULL, "ConsoleHandle = %p\n",
RtlGetCurrentPeb()->ProcessParameters->ConsoleHandle);
handle = CreateFileA("CONOUT$", GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, 0);
ok(handle == INVALID_HANDLE_VALUE &&
(GetLastError() == ERROR_INVALID_HANDLE || broken(GetLastError() == ERROR_ACCESS_DENIED /* winxp */)),
@ -3719,8 +3725,12 @@ static void test_AttachConsole_child(DWORD console_pid)
ok(!res && GetLastError() == ERROR_ACCESS_DENIED,
"AttachConsole returned: %x(%u)\n", res, GetLastError());
todo_wine
ok(RtlGetCurrentPeb()->ProcessParameters->ConsoleHandle != NULL, "ConsoleHandle is NULL\n");
res = FreeConsole();
ok(res, "FreeConsole failed: %u\n", GetLastError());
ok(RtlGetCurrentPeb()->ProcessParameters->ConsoleHandle == NULL, "ConsoleHandle = %p\n",
RtlGetCurrentPeb()->ProcessParameters->ConsoleHandle);
SetStdHandle(STD_ERROR_HANDLE, pipe_out);
@ -3728,6 +3738,8 @@ static void test_AttachConsole_child(DWORD console_pid)
ok(res, "AttachConsole failed: %u\n", GetLastError());
ok(pipe_out != GetStdHandle(STD_ERROR_HANDLE), "std handle not set to console\n");
todo_wine
ok(RtlGetCurrentPeb()->ProcessParameters->ConsoleHandle != NULL, "ConsoleHandle is NULL\n");
console = CreateFileA("CONOUT$", GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, 0);
ok(console != INVALID_HANDLE_VALUE, "Could not open console\n");

View File

@ -509,6 +509,9 @@ BOOL WINAPI DECLSPEC_HOTPATCH FreeConsole(void)
RtlEnterCriticalSection( &console_section );
NtClose( RtlGetCurrentPeb()->ProcessParameters->ConsoleHandle );
RtlGetCurrentPeb()->ProcessParameters->ConsoleHandle = NULL;
if (console_flags & CONSOLE_INPUT_HANDLE) NtClose( GetStdHandle( STD_INPUT_HANDLE ));
if (console_flags & CONSOLE_OUTPUT_HANDLE) NtClose( GetStdHandle( STD_OUTPUT_HANDLE ));
if (console_flags & CONSOLE_ERROR_HANDLE) NtClose( GetStdHandle( STD_ERROR_HANDLE ));