fix: release cloned mg_obj refcount after sv_magic#137
Draft
Koan-Bot wants to merge 2 commits into
Draft
Conversation
sv_magic() takes its own SvREFCNT_inc on the obj parameter, but the caller's reference returned by sv_clone() was never released. This leaked one refcount per magic entry per clone call — the cloned tie object's DESTROY never fired. Affects any SV with magic where mg_obj is recursively cloned: tied hashes, arrays, scalars, and other non-skipped magic types. Add t/28-tied-mgobj-leak.t with DESTROY tracking and weakref-based leak detection for tied hashes, arrays, and scalars. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
install-with-cpm@v1 regressed on Perl 5.8-5.22 after a recent cpm update requiring Perl 5.24+. Bump to @v2 for action-based jobs and use direct `cpm install` in the Docker-based Linux matrix (where cpm is pre-installed). Matches the approach approved by @atoomic in PR garu#120. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Fix a refcount leak on the cloned
mg_objin the magic cloning loop.Why
sv_magic()takes its ownSvREFCNT_incon theobjparameter, but thecaller's reference returned by
sv_clone()was never released. Eachclone()call on a tied variable leaked one refcount per magic entry — the cloned tie
object's
DESTROYnever fired.This affects tied hashes, arrays, scalars, and any SV whose magic chain contains
a recursively-cloned
mg_obj.How
After
sv_magic(clone, obj, ...), callSvREFCNT_dec(obj)whenobjwasproduced by
sv_clone()(tracked via a per-iterationobj_clonedflag).Shared
mg_objreferences (e.g.PERL_MAGIC_qr) are not affected — onlythe cloned path needs the decrement.
Testing
t/28-tied-mgobj-leak.twith 5 tests covering tied hashes, arrays, and scalars🤖 Generated with Claude Code
Quality Report
Changes: 3 files changed, 131 insertions(+)
Code scan: clean
Tests: passed (OK)
Branch hygiene: clean
Generated by Kōan post-mission quality pipeline