This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
stop /$unchanging/ leaking
authorDavid Mitchell <davem@iabyn.com>
Wed, 1 Aug 2012 12:31:03 +0000 (13:31 +0100)
committerDavid Mitchell <davem@iabyn.com>
Wed, 1 Aug 2012 12:35:40 +0000 (13:35 +0100)
9f141731d83a1ac6294a5580a5b11ff41490309a, part of the re_eval jumbo fix,
introduced a leak. It incremented the ref count of a run-time regex each
time it was re-used, i.e. where the pattern hadn't changed.

regcomp.c
t/op/svleak.t

index 2bda5da..9e16aa0 100644 (file)
--- a/regcomp.c
+++ b/regcomp.c
@@ -5693,7 +5693,6 @@ Perl_re_op_compile(pTHX_ SV ** const patternp, int pat_count,
        runtime_code = S_has_runtime_code(aTHX_ pRExC_state, expr, pm_flags,
                                            exp, plen);
        if (!runtime_code) {
-           ReREFCNT_inc(old_re);
            if (used_setjump) {
                JMPENV_POP;
            }
index df10953..4a92bc7 100644 (file)
@@ -13,7 +13,7 @@ BEGIN {
        or skip_all("XS::APItest not available");
 }
 
-plan tests => 21;
+plan tests => 22;
 
 # run some code N times. If the number of SVs at the end of loop N is
 # greater than (N-1)*delta at the end of loop 1, we've got a leak
@@ -160,3 +160,9 @@ leak(2, 0,
 }
 
 leak(2,0,sub { !$^V }, '[perl #109762] version object in boolean context');
+
+
+# [perl #114356] run-time rexexp with unchanging pattern got
+# inflated refcounts
+
+leak(2, 0, sub { eval q{ my $x = "x"; "abc" =~ /$x/ for 1..5 } }, '#114356');