Skip to content

Commit 88a35d6

Browse files
committed
Fix leak when smartmatching against a coderef
Previously, when smartmatching against a code reference, the return value would be leaked. This fixes that leak.
1 parent c3ddef3 commit 88a35d6

File tree

2 files changed

+4
-5
lines changed

2 files changed

+4
-5
lines changed

pp_ctl.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5888,17 +5888,13 @@ S_do_smartmatch(pTHX_ HV *seen_this, HV *seen_other, const bool copied)
58885888
sm_any_sub:
58895889
DEBUG_M(Perl_deb(aTHX_ " applying rule Any-CodeRef\n"));
58905890
ENTER_with_name("smartmatch_coderef");
5891-
SAVETMPS;
58925891
PUSHMARK(SP);
58935892
PUSHs(d);
58945893
PUTBACK;
58955894
c = call_sv(e, G_SCALAR);
58965895
SPAGAIN;
58975896
if (c == 0)
58985897
PUSHs(&PL_sv_no);
5899-
else if (SvTEMP(TOPs))
5900-
SvREFCNT_inc_void(TOPs);
5901-
FREETMPS;
59025898
LEAVE_with_name("smartmatch_coderef");
59035899
RETURN;
59045900
}

t/op/svleak.t

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ BEGIN {
1515

1616
use Config;
1717

18-
plan tests => 153;
18+
plan tests => 154;
1919

2020
# run some code N times. If the number of SVs at the end of loop N is
2121
# greater than (N-1)*delta at the end of loop 1, we've got a leak
@@ -646,6 +646,9 @@ my $refcount;
646646
PERL
647647
}
648648

649+
my $one = 1;
650+
leak 2, 0, sub { 1 ~~ sub { 1 + $one } }, 'Smartmatch doesn\'t leak';
651+
649652
# the initial implementation of the require hook had some leaks
650653

651654
sub hook::before { $_[0] = "NoSuchFile2" if $_[0] =~/ NoSuch/;

0 commit comments

Comments
 (0)