Stop run-time regexp blocks from leaking regexps
authorFather Chrysostomos <sprout@cpan.org>
Wed, 31 Oct 2012 17:02:03 +0000 (10:02 -0700)
committerFather Chrysostomos <sprout@cpan.org>
Fri, 2 Nov 2012 01:09:59 +0000 (18:09 -0700)
commit2ac1304871ec6cab968bd70b187c30f52d230288
treec423cb34df7c9782780e1c3f56a8571cf38edfa9
parentddac780e51876b4ded3e018ba6117a0f0f69dfe1
Stop run-time regexp blocks from leaking regexps

This was leaking like a sieve: $var = '(?{})'; /stuff$var/;

When a run-time regular expression has code blocks in it,
those are compiled separately inside their own qr thingy (see
S_compile_runtime_code in regcomp.c).

In re_op_compile, the newly-compiled code blocks are stored in
pRExC_state->code_blocks, which is a mallocked array.  That array also
holds reference counts on the regular expressions from which the code
blocks derive their existence.  When the whole regular expression is
compiled, the code blocks are fetched from that array, and the new
regular expression ends up holding a reference count on those code
block‚Äôs originating regular expressions.

The reference counts that pRExC_state->code_blocks had were not low-
ered when pRExC_state->code_blocks was freed, except for qr/stuff$var/
(because the qr// would take ownership of those reference counts,
which would be lowered when the outer qr// itself was freed).
regcomp.c
t/op/svleak.t