This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Fix my_pclose segfault
[perl5.git] / util.c
diff --git a/util.c b/util.c
index 0dd9fad..c9174fe 100644 (file)
--- a/util.c
+++ b/util.c
@@ -1,6 +1,6 @@
 /*    util.c
  *
- *    Copyright (c) 1991-2000, Larry Wall
+ *    Copyright (c) 1991-2001, Larry Wall
  *
  *    You may distribute under the terms of either the GNU General Public
  *    License or the Artistic License, as specified in the README file.
@@ -2455,8 +2455,12 @@ Perl_my_popen(pTHX_ char *cmd, char *mode)
        PerlLIO_close(pp[0]);
        did_pipes = 0;
        if (n) {                        /* Error */
+           int pid2, status;
            if (n != sizeof(int))
                Perl_croak(aTHX_ "panic: kid popen errno read");
+           do {
+               pid2 = wait4pid(pid, &status, 0);
+           } while (pid2 == -1 && errno == EINTR);
            errno = errkid;             /* Propagate errno from kid */
            return Nullfp;
        }
@@ -2659,7 +2663,9 @@ Perl_my_pclose(pTHX_ PerlIO *ptr)
     LOCK_FDPID_MUTEX;
     svp = av_fetch(PL_fdpid,PerlIO_fileno(ptr),TRUE);
     UNLOCK_FDPID_MUTEX;
-    pid = SvIVX(*svp);
+    pid = SvIV(*svp);
+    if (!pid)
+        return 0;
     SvREFCNT_dec(*svp);
     *svp = &PL_sv_undef;
 #ifdef OS2