This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Fix for fd leak in IO::File::new_tmpfile
authorGraham Barr <gbarr@ti.com>
Mon, 13 Jan 1997 02:07:59 +0000 (14:07 +1200)
committerChip Salzenberg <chip@atlantic.net>
Wed, 15 Jan 1997 19:24:00 +0000 (07:24 +1200)
Signed-off-by: Graham Barr <gbarr@ti.com>
ext/IO/IO.xs
ext/IO/lib/IO/Handle.pm

index a6eb075..daa22f6 100644 (file)
@@ -121,17 +121,28 @@ fsetpos(handle, pos)
 
 MODULE = IO    PACKAGE = IO::File      PREFIX = f
 
-OutputStream
+SV *
 new_tmpfile(packname = "IO::File")
     char *             packname
+    PREINIT:
+       OutputStream fp;
+       GV *gv;
     CODE:
 #ifdef PerlIO
-       RETVAL = PerlIO_tmpfile();
+       fp = PerlIO_tmpfile();
 #else
-       RETVAL = tmpfile();
+       fp = tmpfile();
 #endif
-    OUTPUT:
-       RETVAL
+       gv = (GV*)SvREFCNT_inc(newGVgen(packname));
+       hv_delete(GvSTASH(gv), GvNAME(gv), GvNAMELEN(gv), G_DISCARD);
+       if (do_open(gv, "+>&", 3, FALSE, 0, 0, fp)) {
+           ST(0) = sv_2mortal(newRV_noinc((SV*)gv));
+           sv_bless(ST(0), gv_stashpv(packname, TRUE));
+       }
+       else {
+           ST(0) = &sv_undef;
+           SvREFCNT_dec(gv);
+       }
 
 MODULE = IO    PACKAGE = IO::Handle    PREFIX = f
 
index af706cf..e271268 100644 (file)
@@ -192,7 +192,7 @@ use SelectSaver;
 require Exporter;
 @ISA = qw(Exporter);
 
-$VERSION = "1.14";
+$VERSION = "1.1401";
 
 @EXPORT_OK = qw(
     autoflush