Skip to content

[3.12] gh-107471: Fix Refleaks in test_import (gh-107569) #107571

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Lib/test/test_import/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ def _ready_to_import(name=None, source=""):
def restore__testsinglephase(*, _orig=_testsinglephase):
# We started with the module imported and want to restore
# it to its nominal state.
sys.modules.pop('_testsinglephase', None)
_orig._clear_globals()
_testinternalcapi.clear_extension('_testsinglephase', _orig.__file__)
import _testsinglephase
Expand Down Expand Up @@ -2110,7 +2111,7 @@ def clean_up():
_interpreters.run_string(interpid, textwrap.dedent(f'''
name = {self.NAME!r}
if name in sys.modules:
sys.modules[name]._clear_globals()
sys.modules.pop(name)._clear_globals()
_testinternalcapi.clear_extension(name, {self.FILE!r})
'''))
_interpreters.destroy(interpid)
Expand Down
1 change: 1 addition & 0 deletions Python/import.c
Original file line number Diff line number Diff line change
Expand Up @@ -1080,6 +1080,7 @@ _extensions_cache_delete(PyObject *filename, PyObject *name)
However, this decref would be problematic if the module def were
dynamically allocated, it were the last ref, and this function
were called with an interpreter other than the def's owner. */
assert(_Py_IsImmortal(entry->value));
entry->value = NULL;

finally:
Expand Down