Change 18378 by gsar@rake on 2002/12/31 04:07:56

        integrate change#18377 from maint-5.6 branch
        
               change#17566 needs to be more defensive about win32_dup2()
               itself calling SetStdHandle() (at least MSVCRT does this)

Affected files ...

... //depot/perl/win32/win32.c#213 integrate

Differences ...

==== //depot/perl/win32/win32.c#213 (text) ====
Index: perl/win32/win32.c
--- perl/win32/win32.c#212~18328~       Tue Dec 17 18:27:10 2002
+++ perl/win32/win32.c  Mon Dec 30 20:07:56 2002
@@ -2750,6 +2750,12 @@
     if ((oldfd = win32_dup(stdfd)) == -1)
         goto cleanup;
 
+    /* save the old std handle (this needs to happen before the
+     * dup2(), since that might call SetStdHandle() too) */
+    OP_REFCNT_LOCK;
+    lock_held = 1;
+    old_h = GetStdHandle(nhandle);
+
     /* make stdfd go to child end of pipe (implicitly closes stdfd) */
     /* stdfd will be inherited by the child */
     if (win32_dup2(p[child], stdfd) == -1)
@@ -2758,10 +2764,7 @@
     /* close the child end in parent */
     win32_close(p[child]);
 
-    /* save the old std handle, and set the std handle */
-    OP_REFCNT_LOCK;
-    lock_held = 1;
-    old_h = GetStdHandle(nhandle);
+    /* set the new std handle (in case dup2() above didn't) */
     SetStdHandle(nhandle, (HANDLE)_get_osfhandle(stdfd));
 
     /* start the child */
@@ -2770,16 +2773,17 @@
        if ((childpid = do_spawn_nowait((char*)command)) == -1)
            goto cleanup;
 
-       /* restore the old std handle */
+       /* revert stdfd to whatever it was before */
+       if (win32_dup2(oldfd, stdfd) == -1)
+           goto cleanup;
+
+       /* restore the old std handle (this needs to happen after the
+        * dup2(), since that might call SetStdHandle() too */
        if (lock_held) {
            SetStdHandle(nhandle, old_h);
            OP_REFCNT_UNLOCK;
            lock_held = 0;
        }
-
-       /* revert stdfd to whatever it was before */
-       if (win32_dup2(oldfd, stdfd) == -1)
-           goto cleanup;
 
        /* close saved handle */
        win32_close(oldfd);
End of Patch.

Reply via email to