mirror of
https://github.com/python/cpython.git
synced 2025-07-15 23:35:23 +00:00
[3.12] gh-107471: Fix Refleaks in test_import (gh-107569) (#107571)
gh-107471: Fix Refleaks in test_import (gh-107569)
gh-107184 introduced a refleak in test_import.SubinterpImportTests (specifically test_singlephase_check_with_setting_and_override and test_single_init_extension_compat). We fix it here by making sure _testsinglephase is removed from sys.modules whenever we clear the runtime's internal state for the module.
The underlying problem is strictly contained in the internal function _PyImport_ClearExtension() (AKA _testinternalcapi.clear_extension()), which is only used in tests.
(This also fixes an intermittent segfault introduced in the same place, in test_disallowed_reimport.)
(cherry picked from commit 017f047183
)
Co-authored-by: Eric Snow <ericsnowcurrently@gmail.com>
This commit is contained in:
parent
f7e16d74ad
commit
12d1c494ae
2 changed files with 3 additions and 1 deletions
|
@ -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:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue