https://github.com/python/cpython/commit/ea8c3e028bca2080c476836b8a5edf0ceb3851b4 commit: ea8c3e028bca2080c476836b8a5edf0ceb3851b4 branch: 3.13 author: Stan Ulbrych <[email protected]> committer: StanFromIreland <[email protected]> date: 2026-05-12T18:35:27Z summary:
[3.13] gh-145376: Fix various reference leaks (GH-145377) (#148661) (cherry picked from commit bd13cc09faaef01635aea85130f33aa8cbb8b177) Co-authored-by: Jelle Zijlstra <[email protected]> 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/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 581c87270ff93f..9d92ca0b2f9f3f 100644 --- a/Modules/main.c +++ b/Modules/main.c @@ -511,6 +511,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/pythonrun.c b/Python/pythonrun.c index 632d2c56a67638..0acb92e96ef9c0 100644 --- a/Python/pythonrun.c +++ b/Python/pythonrun.c @@ -1150,6 +1150,7 @@ _PyErr_Display(PyObject *file, PyObject *unused, PyObject *value, PyObject *tb) if (print_exception_fn == NULL || !PyCallable_Check(print_exception_fn)) { Py_DECREF(traceback_module); + Py_XDECREF(print_exception_fn); goto fallback; } diff --git a/Python/sysmodule.c b/Python/sysmodule.c index 8d47177340d780..261d0fdc002f47 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -1782,7 +1782,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]
