From: Takashi Yano <takashi.yano@nifty.ne.jp>
To: cygwin-patches@cygwin.com
Subject: [PATCH 2/4] Cygwin: pty: Fix memory leak in master_fwd_thread.
Date: Thu, 13 Jan 2022 21:28:09 +0900 [thread overview]
Message-ID: <20220113122811.241-3-takashi.yano@nifty.ne.jp> (raw)
In-Reply-To: <20220113122811.241-1-takashi.yano@nifty.ne.jp>
- If master_fwd_thread is terminated by cygthread::terminate_thread(),
the opportunity to release tmp_pathbuf is missed, resulting in a
memory leak. This patch fixes the issue.
---
winsup/cygwin/fhandler_tty.cc | 6 +++++-
winsup/cygwin/tty.cc | 1 +
winsup/cygwin/tty.h | 1 +
3 files changed, 7 insertions(+), 1 deletion(-)
diff --git a/winsup/cygwin/fhandler_tty.cc b/winsup/cygwin/fhandler_tty.cc
index 16dbc5c0a..f68e80df9 100644
--- a/winsup/cygwin/fhandler_tty.cc
+++ b/winsup/cygwin/fhandler_tty.cc
@@ -2106,7 +2106,9 @@ fhandler_pty_master::close ()
master_ctl = NULL;
}
release_output_mutex ();
- master_fwd_thread->terminate_thread ();
+ get_ttyp ()->stop_fwd_thread = true;
+ WriteFile (to_master_nat, "", 0, NULL, NULL);
+ master_fwd_thread->detach ();
}
}
if (InterlockedDecrement (&master_cnt) == 0)
@@ -2695,6 +2697,8 @@ fhandler_pty_master::pty_master_fwd_thread (const master_fwd_thread_param_t *p)
termios_printf ("ReadFile for forwarding failed, %E");
break;
}
+ if (p->ttyp->stop_fwd_thread)
+ break;
ssize_t wlen = rlen;
char *ptr = outbuf;
if (p->ttyp->pcon_activated)
diff --git a/winsup/cygwin/tty.cc b/winsup/cygwin/tty.cc
index e29d73dcb..789528856 100644
--- a/winsup/cygwin/tty.cc
+++ b/winsup/cygwin/tty.cc
@@ -254,6 +254,7 @@ tty::init ()
last_sig = 0;
mask_flusho = false;
discard_input = false;
+ stop_fwd_thread = false;
}
HANDLE
diff --git a/winsup/cygwin/tty.h b/winsup/cygwin/tty.h
index 25d351a4a..519d7c0d5 100644
--- a/winsup/cygwin/tty.h
+++ b/winsup/cygwin/tty.h
@@ -132,6 +132,7 @@ private:
xfer_dir pcon_input_state;
bool mask_flusho;
bool discard_input;
+ bool stop_fwd_thread;
public:
HANDLE from_master_nat () const { return _from_master_nat; }
--
2.34.1
next prev parent reply other threads:[~2022-01-13 12:29 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-13 12:28 [PATCH 0/4] Some fixes for console and pty Takashi Yano
2022-01-13 12:28 ` [PATCH 1/4] Cygwin: pty, console: Fix deadlock in GDB regarding mutex Takashi Yano
2022-01-13 12:28 ` Takashi Yano [this message]
2022-01-13 12:28 ` [PATCH 3/4] Cygwin: pty: Stop closing and recreating attach_mutex Takashi Yano
2022-01-13 12:28 ` [PATCH 4/4] Cygwin: console: Fix potential deadlock regarding acuqiring mutex Takashi Yano
2022-01-14 9:15 ` [PATCH 0/4] Some fixes for console and pty Corinna Vinschen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220113122811.241-3-takashi.yano@nifty.ne.jp \
--to=takashi.yano@nifty.ne.jp \
--cc=cygwin-patches@cygwin.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).