]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.13] gh-145376: Fix various reference leaks (GH-145377) (#148661)
authorStan Ulbrych <stan@python.org>
Tue, 12 May 2026 18:35:27 +0000 (19:35 +0100)
committerGitHub <noreply@github.com>
Tue, 12 May 2026 18:35:27 +0000 (18:35 +0000)
(cherry picked from commit bd13cc09faaef01635aea85130f33aa8cbb8b177)

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Misc/NEWS.d/next/Core_and_Builtins/2026-02-28-16-46-17.gh-issue-145376.lG5u1a.rst [new file with mode: 0644]
Modules/main.c
Python/pythonrun.c
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 (file)
index 0000000..a5a6908
--- /dev/null
@@ -0,0 +1 @@
+Fix reference leaks in various unusual error scenarios.
index 581c87270ff93f3c31a4676b445f6c07557c0fef..9d92ca0b2f9f3fa249645df162823862dd01f7de 100644 (file)
@@ -511,6 +511,7 @@ pymain_run_interactive_hook(int *exitcode)
     }
 
     if (PySys_Audit("cpython.run_interactivehook", "O", hook) < 0) {
+        Py_DECREF(hook);
         goto error;
     }
 
index 632d2c56a6763895c46ded5f7ab29e02693ab2dd..0acb92e96ef9c006e6a8e57bce1c562f212423b7 100644 (file)
@@ -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;
     }
 
index 8d47177340d780f279d98e2334382be4f29e4b87..261d0fdc002f475e6f2da61086e1581c38a03e55 100644 (file)
@@ -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();