[newlib-cygwin] fork: remove cygpid.N sharedmem on fork failure

Corinna Vinschen corinna@sourceware.org
Tue Feb 5 11:55:00 GMT 2019


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

commit fb3e8bd88b06be6b5e748b99aa50968bb46653a1
Author: Michael Haubenwallner <michael.haubenwallner@ssi-schaefer.com>
Date:   Tue Jun 5 12:40:21 2018 +0200

    fork: remove cygpid.N sharedmem on fork failure
    
    When fork finally fails although both CreateProcess and creating the
    "cygpid.N" shared memory section succeeded, we have to release that
    shared memory section as well - before releasing the process handle.
    Otherways we leave an orphan "cygpid.N" shared memory section, and any
    subsequent cygwin process receiving the same PID fails to initialize.
    
    * fork.cc (frok::parent): Call child.allow_remove in cleanup code.

Diff:
---
 winsup/cygwin/fork.cc | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/winsup/cygwin/fork.cc b/winsup/cygwin/fork.cc
index c083f7a..6f00364 100644
--- a/winsup/cygwin/fork.cc
+++ b/winsup/cygwin/fork.cc
@@ -499,13 +499,16 @@ frok::parent (volatile char * volatile stack_here)
 
 /* Common cleanup code for failure cases */
 cleanup:
+  /* release procinfo before hProcess in destructor */
+  child.allow_remove ();
+
   if (fix_impersonation)
     cygheap->user.reimpersonate ();
   if (locked)
     __malloc_unlock ();
 
   /* Remember to de-allocate the fd table. */
-  if (hchild && !child.hProcess)
+  if (hchild && !child.hProcess) /* no child.procinfo */
     ForceCloseHandle1 (hchild, childhProc);
   if (forker_finished)
     ForceCloseHandle (forker_finished);



More information about the Cygwin-cvs mailing list