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 d089df4..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.
@@ -533,7 +533,7 @@ Perl_new_collate(pTHX_ char *newcoll)
 
     if (! newcoll) {
        if (PL_collation_name) {
-           PL_collation_ix++;
+           ++PL_collation_ix;
            Safefree(PL_collation_name);
            PL_collation_name = NULL;
        }
@@ -544,10 +544,9 @@ Perl_new_collate(pTHX_ char *newcoll)
     }
 
     if (! PL_collation_name || strNE(PL_collation_name, newcoll)) {
-       PL_collation_ix++;
-       if (PL_collation_name)
-           Safefree(PL_collation_name);
-       PL_collation_name = stdize_locale(newcoll);
+       ++PL_collation_ix;
+       Safefree(PL_collation_name);
+       PL_collation_name = stdize_locale(savepv(newcoll));
        PL_collation_standard = (strEQ(newcoll, "C") || strEQ(newcoll, "POSIX"));
 
        {
@@ -606,9 +605,8 @@ Perl_new_numeric(pTHX_ char *newnum)
     }
 
     if (! PL_numeric_name || strNE(PL_numeric_name, newnum)) {
-       if (PL_numeric_name)
-           Safefree(PL_numeric_name);
-       PL_numeric_name = stdize_locale(newnum);
+       Safefree(PL_numeric_name);
+       PL_numeric_name = stdize_locale(savepv(newnum));
        PL_numeric_standard = (strEQ(newnum, "C") || strEQ(newnum, "POSIX"));
        PL_numeric_local = TRUE;
        set_numeric_radix();
@@ -2457,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;
        }
@@ -2661,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