diff options
author | Graham Barr <gbarr@ti.com> | 1997-01-13 14:07:59 +1200 |
---|---|---|
committer | Chip Salzenberg <chip@atlantic.net> | 1997-01-16 07:24:00 +1200 |
commit | a375a877d6d52b8fe1c40e6f3e1bdeb7b23aaa67 (patch) | |
tree | 1c73e92d150936dc67f95f8e6f46fa4278e72d12 /ext/IO/IO.xs | |
parent | 6250ba0abb669fbb694bb58699aa811bdf9bfa1f (diff) | |
download | perl-a375a877d6d52b8fe1c40e6f3e1bdeb7b23aaa67.tar.gz |
Fix for fd leak in IO::File::new_tmpfile
Signed-off-by: Graham Barr <gbarr@ti.com>
Diffstat (limited to 'ext/IO/IO.xs')
-rw-r--r-- | ext/IO/IO.xs | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/ext/IO/IO.xs b/ext/IO/IO.xs index a6eb075964..daa22f6000 100644 --- a/ext/IO/IO.xs +++ b/ext/IO/IO.xs @@ -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 |