winconpty: close the pty host handle after terminating it (#8707)

It rather raises the question as to how we missed this.

Closes #8706
This commit is contained in:
Dustin L. Howett 2021-01-08 02:18:27 -08:00 committed by GitHub
parent 039c80d443
commit 8bef5eefd5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 4 deletions

View file

@ -440,10 +440,11 @@ void ConPtyTests::DiesOnClose()
VERIFY_IS_TRUE(GetExitCodeProcess(piClient.hProcess, &dwExit));
VERIFY_ARE_EQUAL(dwExit, (DWORD)STILL_ACTIVE);
// Stash the pty process, it'll get zero'd after the call to close
const auto hConPtyProcess = pty.hConPtyProcess;
// Duplicate the pty process, it'll get closed and zero'd after the call to close
wil::unique_handle hConPtyProcess{};
THROW_IF_WIN32_BOOL_FALSE(DuplicateHandle(GetCurrentProcess(), pty.hConPtyProcess, GetCurrentProcess(), hConPtyProcess.put(), 0, FALSE, DUPLICATE_SAME_ACCESS));
VERIFY_IS_TRUE(GetExitCodeProcess(hConPtyProcess, &dwExit));
VERIFY_IS_TRUE(GetExitCodeProcess(hConPtyProcess.get(), &dwExit));
VERIFY_ARE_EQUAL(dwExit, (DWORD)STILL_ACTIVE);
Log::Comment(NoThrowString().Format(L"Sleep a bit to let the process attach"));
@ -451,6 +452,6 @@ void ConPtyTests::DiesOnClose()
_ClosePseudoConsoleMembers(&pty);
GetExitCodeProcess(hConPtyProcess, &dwExit);
GetExitCodeProcess(hConPtyProcess.get(), &dwExit);
VERIFY_ARE_NOT_EQUAL(dwExit, (DWORD)STILL_ACTIVE);
}

View file

@ -269,6 +269,7 @@ void _ClosePseudoConsoleMembers(_In_ PseudoConsole* pPty)
}
TerminateProcess(pPty->hConPtyProcess, 0);
CloseHandle(pPty->hConPtyProcess);
pPty->hConPtyProcess = nullptr;
}
// Then take care of the reference handle.