]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.14] gh-145376: Fix various reference leaks (GH-145377) (GH-145712)
authorStan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
Tue, 10 Mar 2026 15:31:02 +0000 (15:31 +0000)
committerGitHub <noreply@github.com>
Tue, 10 Mar 2026 15:31:02 +0000 (16:31 +0100)
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/crossinterp.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 9b2ee103d5266290cf80ed598faa2f6152a09d93..15f51acbcf551f475f4b7d81cea26d3e3a091eb3 100644 (file)
@@ -509,6 +509,7 @@ pymain_run_interactive_hook(int *exitcode)
     }
 
     if (PySys_Audit("cpython.run_interactivehook", "O", hook) < 0) {
+        Py_DECREF(hook);
         goto error;
     }
 
index 80772fcedb46e63730746804b89a81de86cb7520..3b6c0c6e1eda4b8c6b0ee05f59f3e98b909d0a8f 100644 (file)
@@ -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;
     }
index e005a509f6f0619f5d5d1ab9fa03406b144a7183..91c81ac0d8d23743e3c16866e0d538cd4ac6ee92 100644 (file)
@@ -1151,6 +1151,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;
     }
 
index 545b130836e26c7db770a743b270744c7483948b..c97042c99fa71e8e2d70ea518786d2f02de11300 100644 (file)
@@ -1759,7 +1759,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();