diff options
author | Roderick Schertler <roderick@gate.net> | 1997-02-23 14:29:57 -0500 |
---|---|---|
committer | Chip Salzenberg <chip@atlantic.net> | 1997-02-22 02:41:53 +1200 |
commit | 17f91513ac552043d03e11367fc515f8fe1d0145 (patch) | |
tree | 859859bab978e065233d8fbd61d3e0050d6d0029 /ext | |
parent | 7d4a81e59803671feb918aa6228e2daa2c8d2edf (diff) | |
download | perl-17f91513ac552043d03e11367fc515f8fe1d0145.tar.gz |
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 <ilya@math.ohio-state.edu> 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: <pzn2sv722y.fsf@eeyore.ibcinc.com>
Diffstat (limited to 'ext')
-rw-r--r-- | ext/IO/lib/IO/Pipe.pm | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/ext/IO/lib/IO/Pipe.pm b/ext/IO/lib/IO/Pipe.pm index 499856a6c6..1768a4afed 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 |