]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-145376: Fix refleaks and double decref for code in Python/ (#145666)
authorPieter Eendebak <pieter.eendebak@gmail.com>
Tue, 10 Mar 2026 09:46:13 +0000 (10:46 +0100)
committerGitHub <noreply@github.com>
Tue, 10 Mar 2026 09:46:13 +0000 (10:46 +0100)
Python/ceval.c
Python/crossinterp.c
Python/sysmodule.c

index 1e5142f4b456a1d965aa727be8c167fd3b56bc3e..950050a602711646c0f63d2d3a15393561fb580f 100644 (file)
@@ -2243,6 +2243,7 @@ _PyEval_ExceptionGroupMatch(_PyInterpreterFrame *frame, PyObject* exc_value,
             if (f != NULL) {
                 PyObject *tb = _PyTraceBack_FromFrame(NULL, f);
                 if (tb == NULL) {
+                    Py_DECREF(wrapped);
                     return -1;
                 }
                 PyException_SetTraceback(wrapped, tb);
index c8a80e7a9860083155b0ea5709a246ef85b5e1b2..f92927da47532128879f9228d7525fc0ab43cfc4 100644 (file)
@@ -1103,12 +1103,12 @@ _convert_exc_to_TracebackException(PyObject *exc, PyObject **p_tbexc)
     }
 
     PyObject *tbexc = PyObject_Call(create, args, kwargs);
-    Py_DECREF(args);
-    Py_DECREF(kwargs);
-    Py_DECREF(create);
     if (tbexc == NULL) {
         goto error;
     }
+    Py_DECREF(args);
+    Py_DECREF(kwargs);
+    Py_DECREF(create);
 
     *p_tbexc = tbexc;
     return 0;
@@ -1497,7 +1497,7 @@ _PyXI_excinfo_Apply(_PyXI_excinfo *info, PyObject *exctype)
 
     PyObject *formatted = _PyXI_excinfo_format(info);
     PyErr_SetObject(exctype, formatted);
-    Py_DECREF(formatted);
+    Py_XDECREF(formatted);
 
     if (tbexc != NULL) {
         PyObject *exc = PyErr_GetRaisedException();
index 55b4072213d3c2ec62e45b55d28fffddb92dadc9..893a116565e37e7fbbd1edee2d2769aecb1d43c6 100644 (file)
@@ -2499,7 +2499,7 @@ sys_remote_exec_impl(PyObject *module, int pid, PyObject *script)
     }
 
     if (PySys_Audit("sys.remote_exec", "iO", pid, script) < 0) {
-        return NULL;
+        goto error;
     }
 
     debugger_script_path = PyBytes_AS_STRING(path);