develooper Front page | perl.perl5.porters | Postings from January 2020

Re: binmode(IO, ':unix') and open(IO, '+>:unix', undef) leak

Thread Previous | Thread Next
From:
Leon Timmermans
Date:
January 28, 2020 21:18
Subject:
Re: binmode(IO, ':unix') and open(IO, '+>:unix', undef) leak
Message ID:
CAHhgV8h=n+vSDuUZOq31W3+yOZwL4NqMCXEc9ixCMRUVVAcFpw@mail.gmail.com
On Sat, Jan 25, 2020 at 1:49 AM Eric Wong <p5p@yhbt.net> wrote:
>
> Leon Timmermans <fawaka@gmail.com> wrote:
> > On Fri, Jan 24, 2020 at 12:23 PM Eric Wong <p5p@yhbt.net> wrote:
> > >
> > > Hello, I'm getting FD leaks from setting the ":unix" IO layer
> > > using either open(..., '+>:unix', undef) or binmode(IO, ':unix').
> > >
> > > I've reproduced it in current blead[1], 5.24.1 (Debian 9),
> > > 5.28.1 (Debian 10), and 5.30.1 (FreeBSD 11).
> > >
> > > [1] blead @ fb953ad4077a4a0f7b8204f52f3ce71feca190d2
> > >     ("win32: don't set the base address of perl5xx.dll")
> > >
> > > Something seems being accounted for wrong, since
> > > :unix already exists and the PerlIOUnix_setfd refcnt
> > > bump is being triggered again.
> > >
> > > I'm using :unix so the read() perlfunc can pass the length arg
> > > down to the read(2) syscall, and avoiding sysread() since I
> > > want my code to be PerlIO::scalar-compatible.
> > >
> > > See attached script for reproducer.  Thanks.
> >
> > Yeah, «open($fh, '+>:unix', undef)» is implemented as (the equivalent
> > of) «open($fh, '+>', undef); binmode $f, ':unix';», resulting in
> > ":unix:perlio:unix" as layers. This is generally unfortunate and
> > should probably change regardless of this issue.
>
> OK.  Just for my own curiosity, would a long-term solution be to
> pop off the perlio (and any other layers) on binmode(..., ':unix')?

TBH I can't think of any valid reason to do binmode ":unix", and if
you really want to get rid of the buffering layer after opening, :pop
is still there.

Leon

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About