From: Stan Ulbrych Date: Tue, 12 May 2026 18:35:27 +0000 (+0100) Subject: [3.13] gh-145376: Fix various reference leaks (GH-145377) (#148661) X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ea8c3e028bca2080c476836b8a5edf0ceb3851b4;p=thirdparty%2FPython%2Fcpython.git [3.13] gh-145376: Fix various reference leaks (GH-145377) (#148661) (cherry picked from commit bd13cc09faaef01635aea85130f33aa8cbb8b177) Co-authored-by: Jelle Zijlstra --- 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 000000000000..a5a6908757e4 --- /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 581c87270ff9..9d92ca0b2f9f 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 632d2c56a676..0acb92e96ef9 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 8d47177340d7..261d0fdc002f 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();