From a375a877d6d52b8fe1c40e6f3e1bdeb7b23aaa67 Mon Sep 17 00:00:00 2001 From: Graham Barr Date: Mon, 13 Jan 1997 14:07:59 +1200 Subject: Fix for fd leak in IO::File::new_tmpfile Signed-off-by: Graham Barr --- ext/IO/IO.xs | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) (limited to 'ext/IO/IO.xs') 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 -- cgit v1.2.1