]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
[3.12] gh-107471: Fix Refleaks in test_import (gh-107569) (#107571)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Wed, 2 Aug 2023 21:23:15 +0000 (14:23 -0700)
committerGitHub <noreply@github.com>
Wed, 2 Aug 2023 21:23:15 +0000 (23:23 +0200)
commit12d1c494ae236e1a1ce8ae8084f8f9a6b6eb8295
tree04603038424d677bbc0b5af513f6d6d4bd9bc7da
parentf7e16d74adffb8bc890530caebf0a08a6ea89d36
[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 017f047183fa33743f7e36c5c360f5c670032be3)

Co-authored-by: Eric Snow <ericsnowcurrently@gmail.com>
Lib/test/test_import/__init__.py
Python/import.c