summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJarkko Hietaniemi <jhi@iki.fi>2003-01-18 18:36:00 +0000
committerJarkko Hietaniemi <jhi@iki.fi>2003-01-18 18:36:00 +0000
commit9cd675818fc1340670abcf2452a8cad2f8be19ac (patch)
treea65030ff6aab2c8c772a74bfbad42b81a8e4915a
parent28bf64cc65915b53137f29e3b65c22348b6fa9c6 (diff)
parent997ec9b4c5029a8aa56f484e7b625da92e3e0521 (diff)
downloadperl-9cd675818fc1340670abcf2452a8cad2f8be19ac.tar.gz
Integrate from perlio:
[ 18507] Thread-protection for dup/fclose/dup2 scheme of stdio leak avoidance. p4raw-link: @18507 on //depot/perlio: 997ec9b4c5029a8aa56f484e7b625da92e3e0521 p4raw-id: //depot/perl@18514
-rw-r--r--perlio.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/perlio.c b/perlio.c
index de6950b4bc..2d5785baa9 100644
--- a/perlio.c
+++ b/perlio.c
@@ -2708,6 +2708,13 @@ PerlIOStdio_close(pTHX_ PerlIO *f)
}
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 @@ PerlIOStdio_close(pTHX_ PerlIO *f)
/* 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;
}
-
}