X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=perlio.c;h=2d5785baa91a7bd0768a1bb36e4a3d2a2e6b024c;hb=9cd675818fc1340670abcf2452a8cad2f8be19ac;hp=de6950b4bc39710464ab511f6aa18d7ac7533e03;hpb=0678cb22c235366e6443f8ba36afc299093d457c;p=p5sagit%2Fp5-mst-13.2.git diff --git a/perlio.c b/perlio.c index de6950b..2d5785b 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; } - }