Cygwin: pty: Add missing CloseHandle() calls.

- PTY code which support pseudo console has a problem that causes
  handle leaks. Four of these are bug in pty code, and the other
  one seems to be a bug of Windows10. ClosePseudoConsole() fails
  to close one internal handle. This patch fixes the issue.
This commit is contained in:
Takashi Yano
2020-01-14 11:50:04 +09:00
committed by Corinna Vinschen
parent bb7741acf8
commit bb30582a99
2 changed files with 27 additions and 2 deletions

View File

@@ -2233,11 +2233,21 @@ fhandler_pty_master::close ()
/* Terminate helper process */
SetEvent (get_ttyp ()->h_helper_goodbye);
WaitForSingleObject (get_ttyp ()->h_helper_process, INFINITE);
CloseHandle (get_ttyp ()->h_helper_goodbye);
CloseHandle (get_ttyp ()->h_helper_process);
/* FIXME: Pseudo console can be accessed via its handle
only in the process which created it. What else can we do? */
if (master_pid_tmp == myself->pid)
/* Release pseudo console */
ClosePseudoConsole (get_pseudo_console ());
{
/* ClosePseudoConsole() seems to have a bug that one
internal handle remains opened. This causes handle leak.
This is a workaround for this problem. */
HPCON_INTERNAL *hp = (HPCON_INTERNAL *) get_pseudo_console ();
HANDLE tmp = hp->hConHostProcess;
/* Release pseudo console */
ClosePseudoConsole (get_pseudo_console ());
CloseHandle (tmp);
}
get_ttyp ()->switch_to_pcon_in = false;
get_ttyp ()->switch_to_pcon_out = false;
}
@@ -3208,6 +3218,8 @@ fhandler_pty_master::setup_pseudoconsole ()
TRUE, EXTENDED_STARTUPINFO_PRESENT,
NULL, NULL, &si_helper.StartupInfo, &pi_helper);
WaitForSingleObject (hello, INFINITE);
CloseHandle (hello);
CloseHandle (pi_helper.hThread);
/* Retrieve pseudo console handles */
DWORD rLen;
char buf[64];