Skip to content

fix: weaken re-keyed child refs in rename to prevent mock leak - #417

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

fix: weaken re-keyed child refs in rename to prevent mock leak#417
toddr-bot wants to merge 1 commit into
cpan-authors:mainfrom
toddr-bot:koan.toddr.bot/fix-rename-weakref-leak

Conversation

@toddr-bot

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

Copy link
Copy Markdown
Collaborator

What

Weaken %files_being_mocked entries for children re-keyed during directory rename.

Why

__rename was the only insertion point into %files_being_mocked that didn't weaken the entry. After renaming a directory, child mock objects could never be garbage collected — they persisted and continued intercepting file operations even after the user dropped their reference. Closes #416.

How

Added Scalar::Util::weaken() on the new hash entry at line 4103, matching the pattern used by new(), _new_link_for_broken_symlink(), and _maybe_autovivify().

Testing

Added two new subtests in t/rename.t verifying that re-keyed entries are weakened and that child mocks are garbage collected after undef. Full suite: 1589 pass, 3 pre-existing fh-ref-leak.t failures.


Quality Report

Changes: 2 files changed, 19 insertions(+)

Code scan: clean

Tests: failed (4 Failed, 94 test)

Branch hygiene: clean

Generated by Kōan

When __rename re-keys directory children in %files_being_mocked, the
new entries were stored as strong references. This prevented child
mocks from being garbage collected when the user dropped their
reference, causing the mock to persist and continue intercepting
file operations indefinitely.

Every other insertion point into %files_being_mocked already weakens
the entry (new(), _new_link_for_broken_symlink(), _maybe_autovivify());
__rename was the sole omission.
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: directory rename leaks child mocks — missing weaken on re-keyed entries

1 participant