From 60587c64e9a1d3f951cdaae1b642174b083acc1a Mon Sep 17 00:00:00 2001 From: Yongtao Huang Date: Wed, 28 Jan 2026 23:15:06 +0800 Subject: [PATCH 1/2] Fix refcount leak in `finalize_remove_modules()` `PyIter_Next()` returns a new reference, but `finalize_remove_modules()` failed to DECREF `key` when `PyObject_GetItem()`` returns NULL. Fix by DECREF'ing `key` before continuing. Signed-off-by: Yongtao Huang --- Python/pylifecycle.c | 1 + 1 file changed, 1 insertion(+) diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c index 88dbdb6d139c5f..d3ed08de1d15d3 100644 --- a/Python/pylifecycle.c +++ b/Python/pylifecycle.c @@ -1622,6 +1622,7 @@ finalize_remove_modules(PyObject *modules, int verbose) PyObject *value = PyObject_GetItem(modules, key); if (value == NULL) { PyErr_FormatUnraisable("Exception ignored while removing modules"); + Py_DECREF(key); continue; } CLEAR_MODULE(key, value); From 7aa26464fddb88f0f96feba2a65135bf12ce6ad6 Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Thu, 29 Jan 2026 02:18:10 +0000 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../2026-01-29-02-18-08.gh-issue-144307.CLbm_o.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Core_and_Builtins/2026-01-29-02-18-08.gh-issue-144307.CLbm_o.rst diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2026-01-29-02-18-08.gh-issue-144307.CLbm_o.rst b/Misc/NEWS.d/next/Core_and_Builtins/2026-01-29-02-18-08.gh-issue-144307.CLbm_o.rst new file mode 100644 index 00000000000000..d6928e643dccd3 --- /dev/null +++ b/Misc/NEWS.d/next/Core_and_Builtins/2026-01-29-02-18-08.gh-issue-144307.CLbm_o.rst @@ -0,0 +1 @@ +Prevent a reference leak in module teardown at interpreter finalization.