Repository navigation
Fix reference/resource leaks on three C-extension error paths - #1381
Conversation
- items-view __contains__ (views.h): when the candidate is a generic sequence, element 0 was fetched and owned, then a failure reading element 1 returned -1 without releasing element 0. - md_repr (hashtable.h): the 'changed during iteration' guard did a bare return NULL, leaking the PyUnicodeWriter; use goto fail to discard it. - md_next (hashtable.h): when _md_ensure_key() fails (low memory) after the identity out-param was already set, release it before cleanup nulls it. Adds a deterministic refcount regression test for the __contains__ leak and a functional test for the repr-during-mutation path.
There was a problem hiding this comment.
@devdanzin Seems the workflow fails with spelling issues. A helpful reminder would be to
pip install pre-commit or uv pip install pre-commit and then run pre-commit run --all-files to fix or find the spelling mistakes that are preventing this PR from passing.
Confidence Score: 5/5Safe to merge based on focused execution of the affected C-extension error paths. No blocking failure remains.
What T-Rex did
Reviews (5): Last reviewed commit: "Update CHANGES/1381.bugfix.rst" | Re-trigger Greptile |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1381 +/- ##
=======================================
Coverage 99.86% 99.87%
=======================================
Files 29 29
Lines 3808 3852 +44
Branches 282 284 +2
=======================================
+ Hits 3803 3847 +44
Misses 3 3
Partials 2 2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Thanks, @devdanzin ! |
What do these changes do?
Three leaks on error paths in the C extension:
items-view__contains__(_multilib/views.h) fetched and owned element 0 of a candidate pair,then returned on an element-1 failure without releasing element 0.
md_repr(_multilib/hashtable.h) did a barereturn NULLon the "changed during iteration" guard,leaking its
PyUnicodeWriter; it nowgoto failto discard it.md_next(_multilib/hashtable.h) leaked the identity reference when key materialisation failedunder low memory.
C-extension-only concerns (the pure-Python backend relies on the GC); no pure-Python change is needed.
Are there changes in behavior for the user?
No user-visible behavior change; these are leak fixes on error paths.
Is it a substantial burden for the maintainers to support this?
No. Small, localized changes.
Related issue number
Findings from the C-extension analysis report #1306.
Checklist
CONTRIBUTORS.txtin this repoCHANGES/folder