This is the mail archive of the
cygwin-patches
mailing list for the Cygwin project.
[PATCH 4/5] Cygwin: FIFO: close connect_evt handles as soon as possible
- From: Ken Brown <kbrown at cornell dot edu>
- To: "cygwin-patches at cygwin dot com" <cygwin-patches at cygwin dot com>
- Date: Sat, 20 Apr 2019 18:58:50 +0000
- Subject: [PATCH 4/5] Cygwin: FIFO: close connect_evt handles as soon as possible
- References: <20190420185834.4228-1-kbrown@cornell.edu>
Keeping them open too long can cause an attempt to close them twice
after a fork or exec.
---
winsup/cygwin/fhandler_fifo.cc | 17 ++++++++++-------
1 file changed, 10 insertions(+), 7 deletions(-)
diff --git a/winsup/cygwin/fhandler_fifo.cc b/winsup/cygwin/fhandler_fifo.cc
index 0e4bf3aee..3ee307bcc 100644
--- a/winsup/cygwin/fhandler_fifo.cc
+++ b/winsup/cygwin/fhandler_fifo.cc
@@ -363,6 +363,7 @@ fhandler_fifo::listen_client_thread ()
break;
}
}
+ HANDLE evt = NULL;
switch (status)
{
case STATUS_SUCCESS:
@@ -371,6 +372,9 @@ fhandler_fifo::listen_client_thread ()
fc.state = fc_connected;
nconnected++;
set_pipe_non_blocking (fc.fh->get_handle (), true);
+ evt = InterlockedExchangePointer (&fc.connect_evt, NULL);
+ if (evt)
+ CloseHandle (evt);
fifo_client_unlock ();
break;
case STATUS_PIPE_LISTENING:
@@ -400,6 +404,8 @@ fhandler_fifo::listen_client_thread ()
}
}
out:
+ if (ret < 0)
+ debug_printf ("exiting lct with error, %E");
ResetEvent (read_ready);
return ret;
}
@@ -829,14 +835,15 @@ int
fifo_client_handler::close ()
{
int res = 0;
+ HANDLE evt = InterlockedExchangePointer (&connect_evt, NULL);
+ if (evt)
+ CloseHandle (evt);
if (fh)
{
res = fh->fhandler_base::close ();
delete fh;
}
- if (connect_evt)
- CloseHandle (connect_evt);
return res;
}
@@ -913,11 +920,7 @@ fhandler_fifo::dup (fhandler_base *child, int flags)
if (!DuplicateHandle (GetCurrentProcess (), fc_handler[i].fh->get_handle (),
GetCurrentProcess (),
&fhf->fc_handler[i].fh->get_handle (),
- 0, true, DUPLICATE_SAME_ACCESS)
- || !DuplicateHandle (GetCurrentProcess (), fc_handler[i].connect_evt,
- GetCurrentProcess (),
- &fhf->fc_handler[i].connect_evt,
- 0, true, DUPLICATE_SAME_ACCESS))
+ 0, true, DUPLICATE_SAME_ACCESS))
{
CloseHandle (fhf->read_ready);
CloseHandle (fhf->write_ready);
--
2.17.0