Skip to content

fix: weaken re-keyed child refs in rename for both mock hashes - #419

Draft
toddr-bot wants to merge 1 commit into
cpan-authors:mainfrom
toddr-bot:koan.toddr.bot/fix-autovivify-rename-weakref
Draft

fix: weaken re-keyed child refs in rename for both mock hashes#419
toddr-bot wants to merge 1 commit into
cpan-authors:mainfrom
toddr-bot:koan.toddr.bot/fix-autovivify-rename-weakref

Conversation

@toddr-bot

@toddr-bot toddr-bot commented Jul 22, 2026

Copy link
Copy Markdown
Collaborator

What

Weaken re-keyed child refs in __rename for both %files_being_mocked and %_autovivify_dirs.

Why

Directory rename re-keys child entries in these two hashes but stored them as strong references — the only insertion points across the codebase that skipped weaken(). This prevents garbage collection: child mocks survive undef after their parent is renamed.

Extends PR #417 (which covered only %files_being_mocked) to also fix %_autovivify_dirs. Supersedes #417. Closes #418.

How

Two Scalar::Util::weaken() calls added to the child re-keying loop in __rename, matching the pattern at every other insertion point.

Testing

  • Added test: child file mock GC'd after parent rename + undef
  • Added test: child autovivify dir mock GC'd after parent rename + undef
  • Full suite: 1593 pass, 3 pre-existing fh-ref-leak.t failures

Quality Report

Changes: 2 files changed, 33 insertions(+)

Code scan: clean

Tests: failed (4 Failed, 94 test)

Branch hygiene: clean

Generated by Kōan

Directory rename re-keys child entries in %files_being_mocked and
%_autovivify_dirs but stored them as strong references, preventing
garbage collection when the mock variable goes out of scope.

Add Scalar::Util::weaken() after both re-keying assignments in the
__rename child loop, matching every other insertion point into these
hashes.

Supersedes PR cpan-authors#417 which only covered %files_being_mocked.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: rename child re-keying leaks mocks in both %files_being_mocked and %_autovivify_dirs

1 participant