Repository navigation
Drop dead retry loop in md_clone_from_ht and fix suspend comments - #1486
Merged
asvetlov merged 2 commits intoSep 20, 2026
Merged
Conversation
An automated review of aio-libs#1484 flagged md_readonly_find_next()'s allocation as a potential use-after-free, reasoning that a blocking PyMem_Malloc() could transiently suspend the critical section. That claim does not hold: per aio-libs#1469, PyMem_Malloc() never suspends an acquired critical section, so the finding was a false positive. The same false premise was still present elsewhere in hashtable.h. md_clone_from_ht() carried the exact retry-on-staleness pattern aio-libs#1469 already proved dead in _md_resize(), just never cleaned up there; drop it the same way. _md_del_at(), _md_del_at_for_upd() and _md_replace() attributed their (real) suspension risk to "the same allocator lock as PyMem_Malloc()", a comment that no longer exists anywhere in the file; reworded those comments to name the actual mechanism, a decref running a finalizer or weakref callback. No behavior change; verified against the C extension (default and free-threaded debug + ASan/UBSan builds) and the pure-Python backend.
asvetlov
marked this pull request as ready for review
September 20, 2026 13:31
Contributor
|
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.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 do these changes do?
An automated review of #1484 flagged
md_readonly_find_next()'s allocationas a potential use-after-free, reasoning that a blocking
PyMem_Malloc()call could transiently suspend the held critical section. That mechanism
does not exist: per #1469,
PyMem_Malloc()never suspends an acquiredcritical section on the free-threaded build, so the finding was a false
positive there.
Chasing the same claim through the rest of
hashtable.hturned up tworeal issues.
md_clone_from_ht()still carried the exactretry-on-staleness loop #1469 already proved dead in
_md_resize(), justnever cleaned up here; this drops it the same way.
_md_del_at(),_md_del_at_for_upd()and_md_replace()have a real suspension risk(a decref of the old key/value can run a finalizer or weakref callback),
but their comments wrongly attributed it to "the same allocator lock as
PyMem_Malloc()", pointing at a comment that no longer exists anywhere inthe file after #1469; reworded those to name the actual mechanism.
Are there changes in behavior for the user?
No.
Is it a substantial burden for the maintainers to support this?
No; this only touches internal comments and removes unreachable code in
one free-threaded-only helper.
Related issue number
Related to #1484 and #1469, not closing either.
Checklist
touched paths are already exercised by the existing suite on both
backends
CONTRIBUTORS.txt-- N/A, no such file in this repoCHANGES/foldermake doc-spellingpasses and any new technical words are added todocs/spelling_wordlist.txtDrafted with Claude Code (Claude Sonnet 5); reviewed by :user:
asvetlov.Agent run details (optional, for reviewers)
Tests (isolated venvs, this branch rebased onto current upstream master):
pytest tests -q-- 2059 passedMULTIDICT_DEBUG_BUILD=1):pytest tests -q -k "not test_leak" --no-cov-- 2049 passedMULTIDICT_ASAN_BUILD=1): same command underLD_PRELOAD=libasan.so ASAN_OPTIONS=detect_leaks=0-- 2049 passed, no sanitizer reportsMULTIDICT_NO_EXTENSIONS=1,pytest --no-c-extensions --no-cov): 1037 passedLint:
make doc-spellingpasses; pre-commit hooks (clang-format, changelog filename/role checks) passed on commit.