gh-98253: fix refleak issue in typing.py #98591
Open
+8
−3
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.
The
typing
module internally uses LRU caches to memoize the result oftype-related computations. These LRU caches have the potential to introduce
difficult-to-find reference leaks spanning multiple extension modules.
Suppose that a binary extension module
a
leaks a reference to a typea.A
with typed function signatures.
The leaked type
a.A
will induce a secondary refleak of thetyping
LRUcaches, which will at this point cause tertiary leaks in entirely unrelated
extension modules. In this way, a benign refleak in any extension can cause
difficult-to-debug leaks everywhere else.
This commit fixes this by removing the direct reference from
a.A
totyping
implementation details.