public inbox for cygwin-cvs@sourceware.org
help / color / mirror / Atom feed
* [newlib-cygwin] Cygwin: FIFO: duplicate the i/o handle when opening a duplexer
@ 2019-04-23 12:17 Ken Brown
  0 siblings, 0 replies; only message in thread
From: Ken Brown @ 2019-04-23 12:17 UTC (permalink / raw)
  To: cygwin-cvs

https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=ef269531a96b649ae27395f272cf95aa2c7062fa

commit ef269531a96b649ae27395f272cf95aa2c7062fa
Author: Ken Brown <kbrown@cornell.edu>
Date:   Sat Apr 20 11:49:35 2019 -0400

    Cygwin: FIFO: duplicate the i/o handle when opening a duplexer
    
    Don't use the same i/o handle for the first client handler as is used
    for the fhandler itself; this can lead to a later attempt to close the
    same handle twice.  Instead use a duplicate.

Diff:
---
 winsup/cygwin/fhandler_fifo.cc | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/winsup/cygwin/fhandler_fifo.cc b/winsup/cygwin/fhandler_fifo.cc
index 409144f..0a6dc05 100644
--- a/winsup/cygwin/fhandler_fifo.cc
+++ b/winsup/cygwin/fhandler_fifo.cc
@@ -480,7 +480,14 @@ fhandler_fifo::open (int flags, mode_t)
 	  res = error_errno_set;
 	  goto out;
 	}
-      fh->set_handle (ph);
+      if (!DuplicateHandle (GetCurrentProcess (), ph, GetCurrentProcess (),
+			    &fh->get_handle (), 0, true, DUPLICATE_SAME_ACCESS))
+	{
+	  res = error_set_errno;
+	  fh->close ();
+	  delete fh;
+	  goto out;
+	}
       fh->set_flags (flags);
       if (!(connect_evt = create_event ()))
 	{


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2019-04-23 12:17 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-04-23 12:17 [newlib-cygwin] Cygwin: FIFO: duplicate the i/o handle when opening a duplexer Ken Brown

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).