Skip to content

Fix Python reference leaks in message and native helpers - #256

Open
drebbe-intrepid wants to merge 3 commits into
masterfrom
codex/fix-243-reference-leaks
Open

drebbe-intrepid wants to merge 3 commits into
masterfrom
codex/fix-243-reference-leaks

Conversation

@drebbe-intrepid

@drebbe-intrepid drebbe-intrepid commented Sep 16, 2026

Copy link
Copy Markdown
Collaborator

Repeated message attribute reads and native helper calls retained Python references. Keep attribute names borrowed and use scoped ownership for imported modules, fetched handle attributes, and newly created capsules, including early-return paths.

Add hardware-free regression tests for both message types and native helper success/failure paths. Native tests compile a minimal mock library and run in a subprocess to isolate library overrides and module monkeypatches.

Fixes #243

Validation:

  • Windows x64, CPython 3.12.10 and 3.14.5: extension rebuilt successfully with MSVC.
  • pytest tests -q: 43 passed on each Python version, including a subprocess suite of 14 native-helper tests.
  • Regression suite failed against the baseline extension; repeated generic attribute reads and helper calls grew reference counts.
  • git diff --check: passed.
  • No hardware accessed.

The separate reopen/status bug in SetHandle is tracked by #245 and intentionally remains outside this ownership fix. Combined integration requires review of that overlapping setter change.

Review gate: independent critic /root/critic_243 and builder explicitly agree with commit f0a25f9 (reviewed diff SHA256 c7806e4dd4a68f9fc9b977275eff5398bd5d37eabf598c05f83061c1ffc82ad4).

The final review includes five i686 mock export aliases. Both builder and critic independently compiled and inspected the i386 DLL exports; no 32-bit Python runtime was exercised.

Capsule tests compare ownership against a fresh control capsule rather than fixed interpreter-specific counts. An injected extra reference was detected on both CPython 3.12 and 3.14; the critic independently repeated both test runs and sensitivity probes.

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.

[P2] Message attribute reads and native-call helpers leak Python references

1 participant