Change 18514 by jhi@lyta on 2003/01/18 18:36:00

        Integrate from perlio:
        [ 18507]
        Thread-protection for dup/fclose/dup2 scheme of stdio leak
        avoidance.

Affected files ...

... //depot/perl/perlio.c#197 integrate
... //depot/perl/t/io/tell.t#18 integrate

Differences ...

==== //depot/perl/perlio.c#197 (text) ====
Index: perl/perlio.c
--- perl/perlio.c#196~18475~    Sun Jan 12 18:42:47 2003
+++ perl/perlio.c       Sat Jan 18 10:36:00 2003
@@ -2708,6 +2708,13 @@
            }
            else {
                /* Tricky - must fclose(stdio) to free memory but not close(fd) */ 
+#ifdef USE_THREADS
+               /* Sarathy pointed out that another thread could reuse
+                  fd after fclose() but before we dup2() below
+                  so take out a MUTEX to shut them out 
+                */  
+               MUTEX_LOCK(&PerlIO_mutex);
+#endif
                dupfd = PerlLIO_dup(fd);
            }
        }    
@@ -2725,12 +2732,14 @@
            /* We need to restore fd from the saved copy */
            if (PerlLIO_dup2(dupfd,fd) != fd)
              result = -1;
+#ifdef USE_THREADS
+           MUTEX_UNLOCK(&PerlIO_mutex);
+#endif
            if (PerlLIO_close(dupfd) != 0)
              result = -1; 
        }
        return result;
     } 
-
 }
 
 
End of Patch.

Reply via email to