From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2210) id 619E83858D28; Sun, 10 Oct 2021 12:59:19 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 619E83858D28 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Ken Brown To: cygwin-cvs@sourceware.org Subject: [newlib-cygwin] Cygwin: pty: Fix handle leak regarding attach_mutex. X-Act-Checkin: newlib-cygwin X-Git-Author: Takashi Yano X-Git-Refname: refs/heads/master X-Git-Oldrev: 8a09deb1b778ddd815270c079931078d01e147f9 X-Git-Newrev: dcd564f65caa96a9dc5c0d17020b9674a1a36e32 Message-Id: <20211010125919.619E83858D28@sourceware.org> Date: Sun, 10 Oct 2021 12:59:19 +0000 (GMT) X-BeenThere: cygwin-cvs@cygwin.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Cygwin core component git logs List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 10 Oct 2021 12:59:19 -0000 https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=dcd564f65caa96a9dc5c0d17020b9674a1a36e32 commit dcd564f65caa96a9dc5c0d17020b9674a1a36e32 Author: Takashi Yano Date: Sun Oct 10 09:49:53 2021 +0900 Cygwin: pty: Fix handle leak regarding attach_mutex. - If the process having master pty opened is forked, attach_mutex fails to be closed when master is closed. This patch fixes the issue. Diff: --- winsup/cygwin/fhandler_console.cc | 2 +- winsup/cygwin/fhandler_tty.cc | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/winsup/cygwin/fhandler_console.cc b/winsup/cygwin/fhandler_console.cc index ee862b17d..aee5e8284 100644 --- a/winsup/cygwin/fhandler_console.cc +++ b/winsup/cygwin/fhandler_console.cc @@ -57,7 +57,7 @@ fhandler_console::console_state NO_COPY *fhandler_console::shared_console_info; bool NO_COPY fhandler_console::invisible_console; /* Mutex for AttachConsole()/FreeConsole() in fhandler_tty.cc */ -HANDLE NO_COPY attach_mutex; +HANDLE attach_mutex; static inline void acquire_attach_mutex (DWORD t) diff --git a/winsup/cygwin/fhandler_tty.cc b/winsup/cygwin/fhandler_tty.cc index 823dabf73..f523dafed 100644 --- a/winsup/cygwin/fhandler_tty.cc +++ b/winsup/cygwin/fhandler_tty.cc @@ -57,7 +57,7 @@ struct pipe_reply { }; extern HANDLE attach_mutex; /* Defined in fhandler_console.cc */ -static LONG NO_COPY master_cnt = 0; +static LONG master_cnt = 0; inline static bool pcon_pid_alive (DWORD pid); @@ -2042,10 +2042,10 @@ fhandler_pty_master::close () } release_output_mutex (); master_fwd_thread->terminate_thread (); - if (InterlockedDecrement (&master_cnt) == 0) - CloseHandle (attach_mutex); } } + if (InterlockedDecrement (&master_cnt) == 0) + CloseHandle (attach_mutex); /* Check if the last master handle has been closed. If so, set input_available_event to wake up potentially waiting slaves. */