From fb3e8bd88b06be6b5e748b99aa50968bb46653a1 Mon Sep 17 00:00:00 2001 From: Michael Haubenwallner Date: Tue, 5 Jun 2018 12:40:21 +0200 Subject: [PATCH] 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. --- 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 c083f7a02..6f0036433 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);