https://github.com/python/cpython/commit/491ccaf5c7c3a0636de2033e9d4b809f3ae5e361 commit: 491ccaf5c7c3a0636de2033e9d4b809f3ae5e361 branch: 3.15 author: Miss Islington (bot) <[email protected]> committer: vstinner <[email protected]> date: 2026-10-17T02:16:02Z summary:
[3.15] gh-159538: Fix deep chain leak in test_deeply_dotted_name (GH-159576) (#159609) gh-159538: Fix deep chain leak in test_deeply_dotted_name (GH-159576) test_deeply_dotted_name() builds a 10,000-deep chain of lazy import placeholders in a thread with a 256 KiB C stack. Freeing the chain there defers most deallocations to the trashcan, which only drains them once the stack margin recovers. With a stack that small the margin never does, so the deferred objects were leaked when the thread exited, which -R reports as a reference leak on platforms with larger frames such as PPC64LE. Clear the namespace in a cleanup, which runs on the main thread. (cherry picked from commit c84d4b5953f18871ef37b2a95c93de84c66950ef) Co-authored-by: Brittany Reynoso <[email protected]> files: M Lib/test/test_lazy_import/__init__.py diff --git a/Lib/test/test_lazy_import/__init__.py b/Lib/test/test_lazy_import/__init__.py index a4adf50899a7602..59ff1dee53ba508 100644 --- a/Lib/test/test_lazy_import/__init__.py +++ b/Lib/test/test_lazy_import/__init__.py @@ -325,6 +325,9 @@ def test_deeply_dotted_name(self): m.m = m ns = {"__builtins__": {"__lazy_import__": __lazy_import__, "__import__": lambda *args: m}} + # Free the chain on the main thread: a thread with a small C stack + # postpones deep deallocations and never gets back to them. + self.addCleanup(ns.clear) exec("lazy import " + ".".join(["m"] * 10_000) + " as x", ns) with contextlib.suppress(RecursionError): ns["x"].resolve() _______________________________________________ Python-checkins mailing list -- [email protected] To unsubscribe send an email to [email protected] https://mail.python.org/mailman3//lists/python-checkins.python.org Member address: [email protected]
