https://github.com/python/cpython/commit/bd13cc09faaef01635aea85130f33aa8cbb8b177
commit: bd13cc09faaef01635aea85130f33aa8cbb8b177
branch: main
author: Jelle Zijlstra <[email protected]>
committer: encukou <[email protected]>
date: 2026-03-03T16:23:30+01:00
summary:
gh-145376: Fix various reference leaks (GH-145377)
files:
A
Misc/NEWS.d/next/Core_and_Builtins/2026-02-28-16-46-17.gh-issue-145376.lG5u1a.rst
M Modules/main.c
M Python/crossinterp.c
M Python/import.c
M Python/pythonrun.c
M Python/sysmodule.c
diff --git
a/Misc/NEWS.d/next/Core_and_Builtins/2026-02-28-16-46-17.gh-issue-145376.lG5u1a.rst
b/Misc/NEWS.d/next/Core_and_Builtins/2026-02-28-16-46-17.gh-issue-145376.lG5u1a.rst
new file mode 100644
index 00000000000000..a5a6908757e458
--- /dev/null
+++
b/Misc/NEWS.d/next/Core_and_Builtins/2026-02-28-16-46-17.gh-issue-145376.lG5u1a.rst
@@ -0,0 +1 @@
+Fix reference leaks in various unusual error scenarios.
diff --git a/Modules/main.c b/Modules/main.c
index 74e48c94732565..95ba541d98c2e8 100644
--- a/Modules/main.c
+++ b/Modules/main.c
@@ -506,6 +506,7 @@ pymain_run_interactive_hook(int *exitcode)
}
if (PySys_Audit("cpython.run_interactivehook", "O", hook) < 0) {
+ Py_DECREF(hook);
goto error;
}
diff --git a/Python/crossinterp.c b/Python/crossinterp.c
index 6365b995a0d3f7..c8a80e7a986008 100644
--- a/Python/crossinterp.c
+++ b/Python/crossinterp.c
@@ -609,6 +609,7 @@ check_missing___main___attr(PyObject *exc)
// Get the error message.
PyObject *args = PyException_GetArgs(exc);
if (args == NULL || args == Py_None || PyObject_Size(args) < 1) {
+ Py_XDECREF(args);
assert(!PyErr_Occurred());
return 0;
}
diff --git a/Python/import.c b/Python/import.c
index dfc4d5707bfdba..3ed808f67f4149 100644
--- a/Python/import.c
+++ b/Python/import.c
@@ -5642,6 +5642,7 @@ _imp__set_lazy_attributes_impl(PyObject *module, PyObject
*modobj,
module_dict = get_mod_dict(modobj);
if (module_dict == NULL || !PyDict_CheckExact(module_dict)) {
+ Py_DECREF(lazy_submodules);
goto done;
}
diff --git a/Python/pythonrun.c b/Python/pythonrun.c
index ec8c2d12ab27fc..043bdf3433ab57 100644
--- a/Python/pythonrun.c
+++ b/Python/pythonrun.c
@@ -1145,6 +1145,7 @@ _PyErr_Display(PyObject *file, PyObject *unused, PyObject
*value, PyObject *tb)
"traceback",
"_print_exception_bltin");
if (print_exception_fn == NULL || !PyCallable_Check(print_exception_fn)) {
+ Py_XDECREF(print_exception_fn);
goto fallback;
}
diff --git a/Python/sysmodule.c b/Python/sysmodule.c
index 28b2108940c853..55b4072213d3c2 100644
--- a/Python/sysmodule.c
+++ b/Python/sysmodule.c
@@ -1762,7 +1762,7 @@ sys_getwindowsversion_impl(PyObject *module)
PyObject *realVersion = _sys_getwindowsversion_from_kernel32();
if (!realVersion) {
if (!PyErr_ExceptionMatches(PyExc_WindowsError)) {
- return NULL;
+ goto error;
}
PyErr_Clear();
_______________________________________________
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]