This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
eliminate an SAVEFREESV(cv) from PUSHSUB
When a CXt_SUB context is pushed, the reference count of the CV is
increased (and is effectively owned by that context frame). It is
decremented when the context frame is popped.
There was an issue in that the POPSUB was done before the LEAVE,
which meant that at sub exit, the sub could be freed before stuff that
referred to that sub was done (such as lexicals being cleaned up by
SAVEt_CLEARSV).
This was fixed by perl-5.005_02-2095-gb0d9ce3, which split POPSUB
into POPSUB and LEAVESUB with the latter responsible for the decrement.
So for example code might do POPSUB; LEAVE; LEAVSUB.
However this wasn't sufficient, because a similar thing happened during
die, for example
sub d {die}
my $f;
$f = sub {my $x=1; $f = 0; d};
eval{ $f->() };
since all *all* the CXt_SUB contexts were popped with POPSUB/LEAVSUB
*before* LEAVE was called.
I fixed this with perl-5.8.0-3206-gb36bdec, by adding another increment to
the CV and doing a SAVEFREESV(cv), both in PUSHSUB. This meant that
the save stack would hold at least one reference to the CV while being
unwound.
However, v5.19.3-139-g2537512 then changed things so that POPSUB also
did a LEAVE. This means that now, die unwinds the context stack and the
save stack in lockstep, so my second fix is now redundant. So this commit
undoes it, saving an rc++/-- and SAVEFREE(cv) per sub call.