]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
viewvcs: workaround leak in Perl v5.40.x series master
authorEric Wong <e@80x24.org>
Tue, 16 Dec 2025 10:10:25 +0000 (10:10 +0000)
committerEric Wong <e@80x24.org>
Wed, 17 Dec 2025 22:15:05 +0000 (22:15 +0000)
The Perl v5.40.x series introduced a leak in some instances of
anonymous subs (aka `closures').  While Perl v5.42.0 fixes this
leak, distros like Debian 13 will use and support v5.40.x for
many more years and we won't ever encourage users to run a
non-distro Perl installation.

This fixes t/solver_git.t stalling in tests on Debian 13, but
there may be other leaks which are not currently fixed.  More
work will be necessary to ensure other parts of our code don't
leak.  This bug was only noticed since my coding style has
evolved towards making flow control dependent on proper memory
management (via ->DESTROY callbacks and our on_destroy helper).

I really want to eliminating anonymous subs entirely and made
another attempt towards that end.  However, I haven't been able
to figure out how to preserve compatibility with various Plack
(PSGI) middlewares in current use.

Link: https://yhbt.net/mirrors/perl.git/90595091f22dad07b381fd02ff1fb7e158fd8915/s/
lib/PublicInbox/ViewVCS.pm

index 76986f68cab7ca0f2dec993a0bf19389d21ec3c9..2141d5e4531d6a3eb2cdcf67db85bfb3e54f8ce1 100644 (file)
@@ -673,8 +673,12 @@ sub show ($$;$) {
                $l;
        };
        sub {
-               $ctx->{-wcb} = $_[0]; # HTTP write callback
-               $limiter->may_start(\&start_solver, $ctx, \&html_page);
+               # $_[0] is HTTP write callback
+               # deep copy $ctx to workaround leak in Perl 5.40.x series
+               # (v5.42.0 and <= 5.38.x are unaffected, fixed in perl.git
+               # 90595091f22dad07b381fd02ff1fb7e158fd8915:
+               my $xctx = { %$ctx, -wcb => $_[0] };
+               $limiter->may_start(\&start_solver, $xctx, \&html_page);
        };
 }