From: Roderick Schertler Date: Sun, 23 Feb 1997 19:29:57 +0000 (-0500) Subject: Fix fd leak in IO::Pipe X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=17f91513ac552043d03e11367fc515f8fe1d0145;p=p5sagit%2Fp5-mst-13.2.git Fix fd leak in IO::Pipe Subject: Re: Another goof with IO::Pipe? On Fri, 21 Feb 1997 18:51:10 -0500 (EST), Ilya Zakharevich said: > > IO::Pipe basically does: > $fh = $rw ? $me->reader() : $me->writer(); # close the other end > bless $io, "IO::Handle"; > $io->fdopen($fh, $mode); > > In the corresponding place IPC::Open3 adds: > > $fh->close; > > Which one is correct? The ->close is necessary, the IO::Pipe code is leaving two copies of the pipe in the child. It dup()s the pipe onto STDIN/STDOUT, but doesn't then close the pipe. Here's an fd scan of a child whose parent did ->reader: FD Type Mode UID Inode File System FS Type rdev 0 char special 0620 roderick 686 13054,42068 dg/ux 23, 8 1 FIFO special 0000 roderick 23 900, 0 dg/ux -- 2 char special 0620 roderick 686 13054,42068 dg/ux 23, 8 4 FIFO special 0000 roderick 23 900, 0 dg/ux -- fd 4 is original write side of the pipe (the read side was fd 3) which should have been closed by this point. p5p-msgid: --- diff --git a/ext/IO/lib/IO/Pipe.pm b/ext/IO/lib/IO/Pipe.pm index 499856a..1768a4a 100644 --- a/ext/IO/lib/IO/Pipe.pm +++ b/ext/IO/lib/IO/Pipe.pm @@ -14,7 +14,7 @@ use vars qw($VERSION); use Carp; use Symbol; -$VERSION = "1.09"; +$VERSION = "1.0901"; sub new { my $type = shift; @@ -65,6 +65,7 @@ sub _doit { } bless $io, "IO::Handle"; $io->fdopen($fh, $mode); + $fh->close; if ($do_spawn) { $pid = eval { system 1, @_ }; # 1 == P_NOWAIT