summaryrefslogtreecommitdiff
path: root/win32/win32.c
diff options
context:
space:
mode:
authorAndrew Savige <ajsavige@yahoo.com.au>2006-09-20 09:42:31 +1000
committerRafael Garcia-Suarez <rgarciasuarez@gmail.com>2006-09-20 11:53:59 +0000
commit564914cd4f6b4bf8bd455752588c80fe2e116eb0 (patch)
tree0ba400b0de443ce40d9ddf66acb9c3e3433b7ba9 /win32/win32.c
parent196f1508fbd1265748a5d7c65c81c260de51a4d8 (diff)
downloadperl-564914cd4f6b4bf8bd455752588c80fe2e116eb0.tar.gz
Re: [PATCH] Patch for win32.c to fix #38723 and #39531
Message-ID: <20060919134231.87370.qmail@web56407.mail.re3.yahoo.com> p4raw-id: //depot/perl@28873
Diffstat (limited to 'win32/win32.c')
-rw-r--r--win32/win32.c22
1 files changed, 11 insertions, 11 deletions
diff --git a/win32/win32.c b/win32/win32.c
index 7c0af0f11d..49ba63ae93 100644
--- a/win32/win32.c
+++ b/win32/win32.c
@@ -2726,16 +2726,16 @@ win32_popen(const char *command, const char *mode)
if (win32_pipe(p, 512, ourmode) == -1)
return NULL;
- /* save current stdfd */
- 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);
+ /* save current stdfd */
+ if ((oldfd = win32_dup(stdfd)) == -1)
+ goto cleanup;
+
/* 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)
@@ -2757,6 +2757,9 @@ win32_popen(const char *command, const char *mode)
if (win32_dup2(oldfd, stdfd) == -1)
goto cleanup;
+ /* close saved handle */
+ win32_close(oldfd);
+
/* restore the old std handle (this needs to happen after the
* dup2(), since that might call SetStdHandle() too */
if (lock_held) {
@@ -2765,9 +2768,6 @@ win32_popen(const char *command, const char *mode)
lock_held = 0;
}
- /* close saved handle */
- win32_close(oldfd);
-
LOCK_FDPID_MUTEX;
sv_setiv(*av_fetch(w32_fdpid, p[parent], TRUE), childpid);
UNLOCK_FDPID_MUTEX;
@@ -2783,15 +2783,15 @@ cleanup:
/* we don't need to check for errors here */
win32_close(p[0]);
win32_close(p[1]);
+ if (oldfd != -1) {
+ win32_dup2(oldfd, stdfd);
+ win32_close(oldfd);
+ }
if (lock_held) {
SetStdHandle(nhandle, old_h);
OP_REFCNT_UNLOCK;
lock_held = 0;
}
- if (oldfd != -1) {
- win32_dup2(oldfd, stdfd);
- win32_close(oldfd);
- }
return (NULL);
#endif /* USE_RTL_POPEN */