public inbox for cygwin-cvs@sourceware.org
help / color / mirror / Atom feed
* [newlib-cygwin] Cygwin: fhandler_pipe::raw_read: fix handle leak
@ 2021-11-24 14:03 Ken Brown
  0 siblings, 0 replies; only message in thread
From: Ken Brown @ 2021-11-24 14:03 UTC (permalink / raw)
  To: cygwin-cvs

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

commit 6d34b62cb8e192071e193516c23419854c3b4127
Author: Ken Brown <kbrown@cornell.edu>
Date:   Tue Nov 23 10:13:43 2021 -0500

    Cygwin: fhandler_pipe::raw_read: fix handle leak
    
    Slightly rearrange the code to avoid returning without closing the
    event handle.

Diff:
---
 winsup/cygwin/fhandler_pipe.cc | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/winsup/cygwin/fhandler_pipe.cc b/winsup/cygwin/fhandler_pipe.cc
index 3cbd434b7..5195b2807 100644
--- a/winsup/cygwin/fhandler_pipe.cc
+++ b/winsup/cygwin/fhandler_pipe.cc
@@ -284,13 +284,6 @@ fhandler_pipe::raw_read (void *ptr, size_t& len)
   if (!len)
     return;
 
-  if (!(evt = CreateEvent (NULL, false, false, NULL)))
-    {
-      __seterrno ();
-      len = (size_t) -1;
-      return;
-    }
-
   DWORD timeout = is_nonblocking () ? 0 : INFINITE;
   DWORD waitret = cygwait (read_mtx, timeout);
   switch (waitret)
@@ -314,6 +307,15 @@ fhandler_pipe::raw_read (void *ptr, size_t& len)
       len = (size_t) -1;
       return;
     }
+
+  if (!(evt = CreateEvent (NULL, false, false, NULL)))
+    {
+      __seterrno ();
+      len = (size_t) -1;
+      ReleaseMutex (read_mtx);
+      return;
+    }
+
   while (nbytes < len)
     {
       ULONG_PTR nbytes_now = 0;


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

only message in thread, other threads:[~2021-11-24 14:03 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-24 14:03 [newlib-cygwin] Cygwin: fhandler_pipe::raw_read: fix handle leak 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).