[newlib-cygwin/cygwin-3_3-branch] Cygwin: fhandler_pipe::raw_read: fix handle leak

Ken Brown kbrown@sourceware.org
Wed Nov 24 14:03:26 GMT 2021


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

commit 384c78e8a73123734c19132e1732b5be67837c65
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 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 e92d313c7..25a092262 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;


More information about the Cygwin-cvs mailing list