This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Free operand when encountering unmatched ')' in (?[])
authorFather Chrysostomos <sprout@cpan.org>
Thu, 6 Jun 2013 21:07:21 +0000 (14:07 -0700)
committerFather Chrysostomos <sprout@cpan.org>
Fri, 7 Jun 2013 00:53:22 +0000 (17:53 -0700)
I only need to free the operand (current), not the left-paren token
that turns out not to be a paren (lparen).

For lparen to leak, there would have to be two operands in a row on
the charclass parsing stack, which currently never happens.

regcomp.c
t/op/svleak.t

index f5adebc..fa0a840 100644 (file)
--- a/regcomp.c
+++ b/regcomp.c
@@ -11949,6 +11949,7 @@ S_handle_regex_sets(pTHX_ RExC_state_t *pRExC_state, SV** return_invlist, I32 *f
                     || IS_OPERAND(lparen)
                     || SvUV(lparen) != '(')
                 {
+                    SvREFCNT_dec(current);
                     RExC_parse++;
                     vFAIL("Unexpected ')'");
                 }
index 0fb6b24..c8e0354 100644 (file)
@@ -15,7 +15,7 @@ BEGIN {
 
 use Config;
 
-plan tests => 122;
+plan tests => 123;
 
 # 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
@@ -248,6 +248,7 @@ eleak(2,0,'no warnings; /(?[[a]|[b]])/');
 eleak(2,0,'no warnings; /(?[[a]^[b]])/');
 eleak(2,0,'no warnings; /(?[![a]])/');
 eleak(2,0,'no warnings; /(?[\p{Word}])/');
+eleak(2,0,'no warnings; /(?[[a]+)])/');
 
 # These can generate one ref count, but just  once.
 eleak(4,1,'chr(0x100) =~ /[[:punct:]]/');