From: Nicholas Clark Date: Mon, 19 Mar 2007 15:17:27 +0000 (+0000) Subject: PerlIO_exportFILE() and PerlIO_releaseFILE() should manage the fd X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=6b54a40376f816c07bf5262ecec28e130b304cb8;p=p5sagit%2Fp5-mst-13.2.git PerlIO_exportFILE() and PerlIO_releaseFILE() should manage the fd reference counts correctly. p4raw-id: //depot/perl@30633 --- diff --git a/ext/XS/Typemap/Typemap.xs b/ext/XS/Typemap/Typemap.xs index 3e44867..dbb1733 100644 --- a/ext/XS/Typemap/Typemap.xs +++ b/ext/XS/Typemap/Typemap.xs @@ -802,10 +802,11 @@ T_STDIO_close( f ) CODE: /* Get the FILE* */ stream = PerlIO_findFILE( f ); - RETVAL = xsfclose( stream ); /* Release the FILE* from the PerlIO system so that we do not close the file twice */ PerlIO_releaseFILE(f,stream); + /* Must release the file before closing it */ + RETVAL = xsfclose( stream ); OUTPUT: RETVAL diff --git a/perlio.c b/perlio.c index bba198c..ef07055 100644 --- a/perlio.c +++ b/perlio.c @@ -3552,6 +3552,7 @@ PerlIO_exportFILE(PerlIO * f, const char *mode) if ((f2 = PerlIO_push(aTHX_ f, PERLIO_FUNCS_CAST(&PerlIO_stdio), buf, NULL))) { PerlIOStdio *s = PerlIOSelf((f = f2), PerlIOStdio); s->stdio = stdio; + PerlIOUnix_refcnt_inc(fileno(stdio)); /* Link previous lower layers under new one */ *PerlIONext(f) = l; } @@ -3591,6 +3592,9 @@ PerlIO_releaseFILE(PerlIO *p, FILE *f) PerlIOStdio *s = PerlIOSelf(&l, PerlIOStdio); if (s->stdio == f) { dTHX; + const int fd = fileno(f); + if (fd >= 0) + PerlIOUnix_refcnt_dec(fd); PerlIO_pop(aTHX_ p); return; }