From 219b7ac9d562701bbde21d7e17845c4942b83338 Mon Sep 17 00:00:00 2001 From: Yongtao Huang Date: Fri, 30 Jan 2026 02:50:54 +0800 Subject: [PATCH] gh-144307: Fix a reference leak during module teardown (GH-144308) Signed-off-by: Yongtao Huang Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com> --- .../2026-01-29-02-18-08.gh-issue-144307.CLbm_o.rst | 1 + Python/pylifecycle.c | 1 + 2 files changed, 2 insertions(+) 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 000000000000..d6928e643dcc --- /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. diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c index 88dbdb6d139c..d3ed08de1d15 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); -- 2.47.3