Skip to content

Commit

Permalink
winconpty: close the pty host handle after terminating it (microsoft#…
Browse files Browse the repository at this point in the history
…8707)

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

Closes microsoft#8706
  • Loading branch information
DHowett authored and mpela81 committed Jan 28, 2021
1 parent d8e5876 commit 46c8ced
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/winconpty/ft_pty/ConPtyTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -440,17 +440,18 @@ 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"));
Sleep(100);

_ClosePseudoConsoleMembers(&pty);

GetExitCodeProcess(hConPtyProcess, &dwExit);
GetExitCodeProcess(hConPtyProcess.get(), &dwExit);
VERIFY_ARE_NOT_EQUAL(dwExit, (DWORD)STILL_ACTIVE);
}
1 change: 1 addition & 0 deletions src/winconpty/winconpty.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 46c8ced

Please sign in to comment.