diff options
author | Nick Ing-Simmons <nik@tiuk.ti.com> | 2003-01-17 14:05:27 +0000 |
---|---|---|
committer | Nick Ing-Simmons <nik@tiuk.ti.com> | 2003-01-17 14:05:27 +0000 |
commit | 997ec9b4c5029a8aa56f484e7b625da92e3e0521 (patch) | |
tree | 0c5e580836c7d4a901a04da98cf1fa83a3a8aa9d /perlio.c | |
parent | 2022f30b5b153bfc2b0167458d493cc5150f1b5d (diff) | |
download | perl-997ec9b4c5029a8aa56f484e7b625da92e3e0521.tar.gz |
Thread-protection for dup/fclose/dup2 scheme of stdio leak
avoidance.
p4raw-id: //depot/perlio@18507
Diffstat (limited to 'perlio.c')
-rw-r--r-- | perlio.c | 11 |
1 files changed, 10 insertions, 1 deletions
@@ -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; } - } |