summaryrefslogtreecommitdiff
path: root/util.c
diff options
context:
space:
mode:
Diffstat (limited to 'util.c')
-rw-r--r--util.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/util.c b/util.c
index 623c44cf81..e42efe3f11 100644
--- a/util.c
+++ b/util.c
@@ -1962,6 +1962,7 @@ Perl_my_popen_list(pTHX_ char *mode, int n, SV **args)
while ((pid = PerlProc_fork()) < 0) {
if (errno != EAGAIN) {
PerlLIO_close(p[This]);
+ PerlLIO_close(p[that]);
if (did_pipes) {
PerlLIO_close(pp[0]);
PerlLIO_close(pp[1]);
@@ -1976,8 +1977,6 @@ Perl_my_popen_list(pTHX_ char *mode, int n, SV **args)
#undef THAT
#define THIS that
#define THAT This
- /* Close parent's end of _the_ pipe */
- PerlLIO_close(p[THAT]);
/* Close parent's end of error status pipe (if any) */
if (did_pipes) {
PerlLIO_close(pp[0]);
@@ -1990,7 +1989,11 @@ Perl_my_popen_list(pTHX_ char *mode, int n, SV **args)
if (p[THIS] != (*mode == 'r')) {
PerlLIO_dup2(p[THIS], *mode == 'r');
PerlLIO_close(p[THIS]);
+ if (p[THAT] != (*mode == 'r')) /* if dup2() didn't close it */
+ PerlLIO_close(p[THAT]); /* close parent's end of _the_ pipe */
}
+ else
+ PerlLIO_close(p[THAT]); /* close parent's end of _the_ pipe */
#if !defined(HAS_FCNTL) || !defined(F_SETFD)
/* No automatic close - do it by hand */
# ifndef NOFILE
@@ -2012,8 +2015,6 @@ Perl_my_popen_list(pTHX_ char *mode, int n, SV **args)
}
/* Parent */
do_execfree(); /* free any memory malloced by child on fork */
- /* Close child's end of pipe */
- PerlLIO_close(p[that]);
if (did_pipes)
PerlLIO_close(pp[1]);
/* Keep the lower of the two fd numbers */
@@ -2022,6 +2023,9 @@ Perl_my_popen_list(pTHX_ char *mode, int n, SV **args)
PerlLIO_close(p[This]);
p[This] = p[that];
}
+ else
+ PerlLIO_close(p[that]); /* close child's end of pipe */
+
LOCK_FDPID_MUTEX;
sv = *av_fetch(PL_fdpid,p[This],TRUE);
UNLOCK_FDPID_MUTEX;