diff options
author | Father Chrysostomos <sprout@cpan.org> | 2013-06-05 21:40:24 -0700 |
---|---|---|
committer | Ricardo Signes <rjbs@cpan.org> | 2013-07-31 22:35:19 -0400 |
commit | abdbe03f98120e5bab9d1baa2a6f1b98890a864f (patch) | |
tree | f3e97a59560d4b13583324529b35ebf9ae7e5afc | |
parent | f84462707ac6f483f96c5128ce25fc5b9fa2cc85 (diff) | |
download | perl-abdbe03f98120e5bab9d1baa2a6f1b98890a864f.tar.gz |
Don’t leak the /(?[])/ parsing stack on error
Instead of creating the parsing stack and then freeing it after pars-
ing the (?[...]) construct (leaking it whenever one of the various
errors scattered throughout the parsing code occurs), mortalise it to
begin with and let the mortals stack take care of it.
(cherry picked from commit 1e4f088863436a8019c7d864691903ffdafeefda)
-rw-r--r-- | regcomp.c | 3 | ||||
-rw-r--r-- | t/op/svleak.t | 3 |
2 files changed, 3 insertions, 3 deletions
@@ -11729,7 +11729,7 @@ S_handle_regex_sets(pTHX_ RExC_state_t *pRExC_state, SV** return_invlist, I32 *f * been parsed and evaluated to a single operand (or else is a syntax * error), and is handled as a regular operand */ - stack = newAV(); + sv_2mortal((SV *)(stack = newAV())); while (RExC_parse < RExC_end) { I32 top_index = av_tindex(stack); @@ -12049,7 +12049,6 @@ S_handle_regex_sets(pTHX_ RExC_state_t *pRExC_state, SV** return_invlist, I32 *f RExC_end = save_end; SvREFCNT_dec_NN(final); SvREFCNT_dec_NN(result_string); - SvREFCNT_dec_NN(stack); nextchar(pRExC_state); Set_Node_Length(node, RExC_parse - oregcomp_parse + 1); /* MJD */ diff --git a/t/op/svleak.t b/t/op/svleak.t index 642b81d018..8140ded505 100644 --- a/t/op/svleak.t +++ b/t/op/svleak.t @@ -15,7 +15,7 @@ BEGIN { use Config; -plan tests => 114; +plan tests => 115; # 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 @@ -240,6 +240,7 @@ eleak(2,0,'/[pp]/'); eleak(2,0,'/[[:ascii:]]/'); eleak(2,0,'/[[.zog.]]/'); eleak(2,0,'/[.zog.]/'); +eleak(2,0,'no warnings; /(?[])/'); # These can generate one ref count, but just once. eleak(4,1,'chr(0x100) =~ /[[:punct:]]/'); |