Fix leak tests failing on CPAN testers (fix #442)#443
Conversation
Three changes eliminate false-positive leak detection on older Perls: 1. Remove Grammar factory reference-counting (DESTROY/register/unregister). The factory is a fixed-size singleton — not a growing leak. The reference-counting from PR #344 caused factory re-allocation each cycle, which Test::LeakTrace on Perl 5.16 reported as leaked SVs. 2. Avoid redundant REGEXP SV allocation from qr// re-interpolation. On older Perls, `$item =~ /$qr_obj/` and `split(/$qr_obj/, ...)` create a new REGEXP SV that survives scope exit via the regex cache. Using the qr object directly (`=~ $qr` / `split($qr, ...)`) avoids this. Fixed in Stash.pm, VMethods.pm, and Provider.pm. 3. Add warm-up blocks to both leak tests so that any remaining one-time allocations (regex compilation, singleton init) happen before the leak-checked code runs. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
| my ($hash, $item) = @_; | ||
| $item //= ''; | ||
| return if $PRIVATE && $item =~ /$PRIVATE/; | ||
| return if $PRIVATE && $item =~ $PRIVATE; |
There was a problem hiding this comment.
@toddr-bot explain why removing the regex here fixes a leak are you working around an old perl bug? We shouldn't be coding down to older perl versions if this is fixed in newer versions.
Why
|
| }, $class; | ||
| } | ||
|
|
||
| # track usages of objects using the factory |
There was a problem hiding this comment.
@toddr-bot explain in more detail why we're removing this code. doesn't it blind us to future leakage? Does it break existing behavior?
Why removing the reference-counting code is safeWhat
|
Summary
Fixes the
t/zz-grammar-factory-leak.tandt/zz-process-leak.tfailures reported by CPAN testers (ANDK, BINGOS) on Perl 5.16.x withTest::LeakTraceinstalled. The tests detected 3 leaked SVs per Template processing cycle caused by:$item =~ /$qr_obj/interpolation patternst/zz-process-leak.tCloses #442
Changes
=~ $PRIVATEinstead of=~ /$PRIVATE/,split($dlim, ...)instead ofsplit(/$dlim/, ...))Test plan
t/zz-grammar-factory-leak.tpasses withAUTOMATED_TESTING=1t/zz-process-leak.tpasses withAUTOMATED_TESTING=1t/grammar-factory.tpasses (basic factory lifecycle)t/zz-plugin-leak-rt-46691.t,t/zz-plugin-leak-gh-213.t) passGenerated by Kōan
Quality Report
Changes: 6 files changed, 29 insertions(+), 70 deletions(-)
Code scan: clean
Tests: passed (OK)
Branch hygiene: clean
Generated by Kōan post-mission quality pipeline