diff --git a/winsup/cygwin/fhandler/termios.cc b/winsup/cygwin/fhandler/termios.cc index 423ca9ea12..8f01a8b5e7 100644 --- a/winsup/cygwin/fhandler/termios.cc +++ b/winsup/cygwin/fhandler/termios.cc @@ -779,6 +779,10 @@ fhandler_termios::spawn_worker::setup (bool iscygwin, HANDLE h_stdin, fhandler_pty_slave *ptys_primary = NULL; fhandler_console *cons_native = NULL; + /* This may resolve an app execution alias, which allocates cygheap memory. + Do it before child_info_spawn::worker() acquires the cygheap lock. */ + console_app = !iscygwin && is_console_app (pc); + for (int i = 0; i < 3; i ++) { const int chk_order[] = {1, 0, 2}; @@ -811,7 +815,7 @@ fhandler_termios::spawn_worker::setup (bool iscygwin, HANDLE h_stdin, ptys->setup_locale (); } } - if (!iscygwin && ptys_primary && is_console_app (pc)) + if (ptys_primary && console_app) { if (h_stdin == ptys_primary->get_handle_nat ()) stdin_is_ptys = true; @@ -852,9 +856,9 @@ fhandler_termios::spawn_worker::is_attaching (DWORD pid) void fhandler_termios::spawn_worker::wait_for_resume_if_necessary - (path_conv &pc, PROCESS_INFORMATION &pi) + (PROCESS_INFORMATION &pi) { - if (is_attaching (myself->dwProcessId) && is_console_app (pc)) + if (is_attaching (myself->dwProcessId) && console_app) { DWORD t0 = GetTickCount (); while (GetTickCount () - t0 < 40 && !is_attaching (pi.dwProcessId) diff --git a/winsup/cygwin/local_includes/fhandler.h b/winsup/cygwin/local_includes/fhandler.h index d4acdb129f..54511c5894 100644 --- a/winsup/cygwin/local_includes/fhandler.h +++ b/winsup/cygwin/local_includes/fhandler.h @@ -2033,17 +2033,18 @@ class fhandler_termios: public fhandler_base bool ptys_need_cleanup; bool cons_need_cleanup; bool stdin_is_ptys; + bool console_app; tty *ptys_ttyp; public: spawn_worker () : ptys_need_cleanup (false), cons_need_cleanup (false), - stdin_is_ptys (false), ptys_ttyp (NULL) {} + stdin_is_ptys (false), console_app (false), ptys_ttyp (NULL) {} void setup (bool iscygwin, HANDLE h_stdin, path_conv &pc, bool nopcon, bool reset_sendsig, const WCHAR *envblock); bool need_cleanup () { return ptys_need_cleanup || cons_need_cleanup; } void cleanup (); bool is_attaching (DWORD pid); - void wait_for_resume_if_necessary (path_conv &, PROCESS_INFORMATION &); + void wait_for_resume_if_necessary (PROCESS_INFORMATION &); }; }; diff --git a/winsup/cygwin/spawn.cc b/winsup/cygwin/spawn.cc index 7fcc33f5e1..15a121a713 100644 --- a/winsup/cygwin/spawn.cc +++ b/winsup/cygwin/spawn.cc @@ -792,7 +792,7 @@ child_info_spawn::worker (const char *prog_arg, const char *const *argv, DuplicateHandle (GetCurrentProcess (), wr_proc_pipe, pi.hProcess, NULL, 0, false, DUPLICATE_SAME_ACCESS); ResumeThread (pi.hThread); - term_spawn_worker.wait_for_resume_if_necessary (real_path, pi); + term_spawn_worker.wait_for_resume_if_necessary (pi); } if (mode == _P_OVERLAY)