Package: perl
Version: 5.36.0-9
Severity: normal
Tags: upstream

The `open' perlop fails to report EMFILE (Too many open files)
when it fails due to having too many open files.

strace confirms the underlying open(2) syscall does fail with
EMFILE, but Perl misreports `$!' as EINVAL (Invalid argument).

A quick repro to open a lot of temporary files is below

perl -e '@x = map {open my $x, ">", undef or die "open: $!"; $x } (0..0xfffff)'

This also affects Perl 5.32.1 (in Debian bullseye).

I suspect this is because Perl is calling free(3) (or similar)
to release allocations upon open(2) failure and failed to
preserve the value of `errno' prior to calling free(3).

So something like this save_errno use ought to fix it:

        int save_errno = errno;
        free(allocated);
        errno = save_errno;

Thanks in advance for forwarding this to upstream since I don't
agree with the Terms of Service or the JavaScript requirement
of upstream's bug tracker.

Reply via email to