Avoid potentially empty struct.
[p5sagit/p5-mst-13.2.git] / util.c
diff --git a/util.c b/util.c
index 1c40d46..ad91f01 100644 (file)
--- a/util.c
+++ b/util.c
@@ -1113,9 +1113,10 @@ Perl_vmess(pTHX_ const char *pat, va_list *args)
            bool line_mode = (RsSIMPLE(PL_rs) &&
                              SvCUR(PL_rs) == 1 && *SvPVX(PL_rs) == '\n');
            Perl_sv_catpvf(aTHX_ sv, ", <%s> %s %"IVdf,
-                     PL_last_in_gv == PL_argvgv ? "" : GvNAME(PL_last_in_gv),
-                     line_mode ? "line" : "chunk",
-                     (IV)IoLINES(GvIOp(PL_last_in_gv)));
+                          PL_last_in_gv == PL_argvgv ?
+                          "" : GvNAME(PL_last_in_gv),
+                          line_mode ? "line" : "chunk",
+                          (IV)IoLINES(GvIOp(PL_last_in_gv)));
        }
 #ifdef USE_5005THREADS
        if (thr->tid)
@@ -1593,6 +1594,11 @@ Perl_vwarner(pTHX_ U32  err, const char* pat, va_list* args)
 void
 Perl_my_setenv(pTHX_ char *nam, char *val)
 {
+#ifdef USE_ITHREADS
+  /* only parent thread can modify process environment */
+  if (PL_curinterp == aTHX)
+#endif
+  {
 #ifndef PERL_USE_SAFE_PUTENV
     /* most putenv()s leak, so we manipulate environ directly */
     register I32 i=setenv_getix(nam);          /* where does it go? */
@@ -1651,6 +1657,7 @@ Perl_my_setenv(pTHX_ char *nam, char *val)
     (void)putenv(new_env);
 #   endif /* __CYGWIN__ */
 #endif  /* PERL_USE_SAFE_PUTENV */
+  }
 }
 
 #else /* WIN32 || NETWARE */
@@ -2089,6 +2096,7 @@ Perl_my_popen(pTHX_ char *cmd, char *mode)
     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]);
@@ -2106,7 +2114,6 @@ Perl_my_popen(pTHX_ char *cmd, char *mode)
 #undef THAT
 #define THIS that
 #define THAT This
-       PerlLIO_close(p[THAT]);
        if (did_pipes) {
            PerlLIO_close(pp[0]);
 #if defined(HAS_FCNTL) && defined(F_SETFD)
@@ -2116,7 +2123,11 @@ Perl_my_popen(pTHX_ char *cmd, char *mode)
        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]);
        }
+       else
+           PerlLIO_close(p[THAT]);
 #ifndef OS2
        if (doexec) {
 #if !defined(HAS_FCNTL) || !defined(F_SETFD)
@@ -2150,8 +2161,7 @@ Perl_my_popen(pTHX_ char *cmd, char *mode)
 #undef THIS
 #undef THAT
     }
-    do_execfree();     /* free any memory malloced by child on fork */
-    PerlLIO_close(p[that]);
+    do_execfree();     /* free any memory malloced by child on vfork */
     if (did_pipes)
        PerlLIO_close(pp[1]);
     if (p[that] < p[This]) {
@@ -2159,6 +2169,9 @@ Perl_my_popen(pTHX_ char *cmd, char *mode)
        PerlLIO_close(p[This]);
        p[This] = p[that];
     }
+    else
+       PerlLIO_close(p[that]);
+
     LOCK_FDPID_MUTEX;
     sv = *av_fetch(PL_fdpid,p[This],TRUE);
     UNLOCK_FDPID_MUTEX;
@@ -4209,7 +4222,7 @@ S_socketpair_udp (int fd[2]) {
 }
 #endif /*  EMULATE_SOCKETPAIR_UDP */
 
-#if !defined(HAS_SOCKETPAIR) && defined(HAS_SOCKET) && defined(AF_INET) && defined(PF_INET) 
+#if !defined(HAS_SOCKETPAIR) && defined(HAS_SOCKET) && defined(AF_INET) && defined(PF_INET)
 int
 Perl_my_socketpair (int family, int type, int protocol, int fd[2]) {
     /* Stevens says that family must be AF_LOCAL, protocol 0.