In perl.git, the branch blead has been updated <http://perl5.git.perl.org/perl.git/commitdiff/853eb961c1a3b014b5a9510740abc15ccd4383b6?hp=541c9a9b4b15e1200c9d800d9bb862fd9c2dbc32>
- Log ----------------------------------------------------------------- commit 853eb961c1a3b014b5a9510740abc15ccd4383b6 Author: Tony Cook <[email protected]> Date: Tue Feb 21 16:38:36 2017 +1100 (perl #130822) fix an AV leak in Perl_reg_named_buff_fetch Originally noted as a scoping issue by Andy Lester. ----------------------------------------------------------------------- Summary of changes: regcomp.c | 5 +---- t/op/svleak.t | 12 +++++++++++- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/regcomp.c b/regcomp.c index ec7fa3bb94..0a80cedec5 100644 --- a/regcomp.c +++ b/regcomp.c @@ -7894,21 +7894,18 @@ SV* Perl_reg_named_buff_fetch(pTHX_ REGEXP * const r, SV * const namesv, const U32 flags) { - AV *retarray = NULL; SV *ret; struct regexp *const rx = ReANY(r); PERL_ARGS_ASSERT_REG_NAMED_BUFF_FETCH; - if (flags & RXapif_ALL) - retarray=newAV(); - if (rx && RXp_PAREN_NAMES(rx)) { HE *he_str = hv_fetch_ent( RXp_PAREN_NAMES(rx), namesv, 0, 0 ); if (he_str) { IV i; SV* sv_dat=HeVAL(he_str); I32 *nums=(I32*)SvPVX(sv_dat); + AV * const retarray = (flags & RXapif_ALL) ? newAV() : NULL; for ( i=0; i<SvIVX(sv_dat); i++ ) { if ((I32)(rx->nparens) >= nums[i] && rx->offs[nums[i]].start != -1 diff --git a/t/op/svleak.t b/t/op/svleak.t index 89fa63f84d..e4e881d11c 100644 --- a/t/op/svleak.t +++ b/t/op/svleak.t @@ -15,7 +15,7 @@ BEGIN { use Config; -plan tests => 140; +plan tests => 141; # 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 @@ -583,3 +583,13 @@ EOF } ::leak(2, 0, \&codeblocks, q{leaking embedded qr codeblocks}); } + +{ + # Perl_reg_named_buff_fetch() leaks an AV when called with an RE + # with no named captures + sub named { + "x" =~ /x/; + re::regname("foo", 1); + } + ::leak(2, 0, \&named, "Perl_reg_named_buff_fetch() on no-name RE"); +} -- Perl5 Master Repository
