You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Refcount leak in finalize_remove_modules() #144307
There is a reference leak in finalize_remove_modules() (pylifecycle.c).
In the iterator-based cleanup path, PyIter_Next() returns a new reference
for key, but if PyObject_GetItem(modules, key) fails, the code continues
without DECREF'ing key.
The fix is to add Py_DECREF(key) before continue;.
Minimal fix:
PyObject*key;
while ((key=PyIter_Next(iterator))) {
PyObject*value=PyObject_GetItem(modules, key);
if (value==NULL) {
PyErr_FormatUnraisable("Exception ignored while removing modules");
Py_DECREF(key); <--------------------herecontinue;
}
CLEAR_MODULE(key, value);
Py_DECREF(value);
Py_DECREF(key);
}
if (PyErr_Occurred()) {
PyErr_FormatUnraisable("Exception ignored while removing modules");
}
Py_DECREF(iterator);
Activity
gh-144307: Fix a reference leak during module teardown (GH-144308)
pythongh-144307: Fix a reference leak during module teardown (pythonG…
ZeroIntensity commentedon Jan 29, 2026
Backports are on auto-merge, thanks for the fix!
[3.13] pythongh-144307: Fix a reference leak during module teardown (p…
[3.13] gh-144307: Fix a reference leak during module teardown (GH-144308
[3.14] gh-144307: Fix a reference leak during module teardown (GH-144308
pythongh-144307: Fix a reference leak during module teardown (pythonG…