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 24, 2020 23:52
Subject:
Re: binmode(IO, ':unix') and open(IO, '+>:unix', undef) leak
Message ID:
CAHhgV8i7J616wMds3Zc3sTQT-ptrqoiqad1gPr9MXubiou10yA@mail.gmail.com
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.

The problem is that the :unix layer was written with the assumption
that no layers underneath it exist, so it doesn't call the close
method of underlaying layers. The solution is to do just that.

The attached patch (also pushed as smoke-me/leont/unix-close-fix and
PR#17489) should fix this .

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