From: Peter Bierma Date: Thu, 29 Jan 2026 19:18:39 +0000 (-0800) Subject: [3.13] gh-144307: Fix a reference leak during module teardown (GH-144308) (GH-144328) X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=78a37d521e0d99b0ff470c05f4f93b3a7cb56576;p=thirdparty%2FPython%2Fcpython.git [3.13] gh-144307: Fix a reference leak during module teardown (GH-144308) (GH-144328) (cherry picked from commit 219b7ac9d562701bbde21d7e17845c4942b83338) Signed-off-by: Yongtao Huang Co-authored-by: Yongtao Huang Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com> --- 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 bfa1fe4f6036..8ba9b2bd006f 100644 --- a/Python/pylifecycle.c +++ b/Python/pylifecycle.c @@ -1609,6 +1609,7 @@ finalize_remove_modules(PyObject *modules, int verbose) PyObject *value = PyObject_GetItem(modules, key); if (value == NULL) { PyErr_FormatUnraisable("Exception ignored on removing modules"); + Py_DECREF(key); continue; } CLEAR_MODULE(key, value);