Don’t leak with /(?{})$invalid_code_block/
authorFather Chrysostomos <sprout@cpan.org>
Thu, 1 Nov 2012 20:08:17 +0000 (13:08 -0700)
committerFather Chrysostomos <sprout@cpan.org>
Fri, 2 Nov 2012 01:09:59 +0000 (18:09 -0700)
This script was leaking:

$ ./perl -Ilib -wMre=eval -e '$x = "(?{+})"; while(1){eval {/(?{})$x/}}'

The mallocked array that is allocated before compilation to hold the
code blocks was not being freed before the syntax error from the inner
pattern ($x) was propagated.

regcomp.c

index ef380ab..3bd8475 100644 (file)
--- a/regcomp.c
+++ b/regcomp.c
@@ -5096,7 +5096,10 @@ S_compile_runtime_code(pTHX_ RExC_state_t * const pRExC_state,
        qr_ref = POPs;
        PUTBACK;
        if (SvTRUE(ERRSV))
+       {
+           Safefree(pRExC_state->code_blocks);
            Perl_croak(aTHX_ "%s", SvPVx_nolen_const(ERRSV));
+       }
        assert(SvROK(qr_ref));
        qr = SvRV(qr_ref);
        assert(SvTYPE(qr) == SVt_REGEXP && RX_ENGINE((REGEXP*)qr)->op_comp);