]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-136017: avoid decref in rich compare for bool objects (#136018)
authorPieter Eendebak <pieter.eendebak@gmail.com>
Fri, 27 Jun 2025 09:01:51 +0000 (11:01 +0200)
committerGitHub <noreply@github.com>
Fri, 27 Jun 2025 09:01:51 +0000 (14:31 +0530)
Objects/object.c

index 4d60128b092c2274890c26f5828c76c0d6f20ac0..1223983753ac46b1e8b386fc02ae741aba4ebf5f 100644 (file)
@@ -1131,11 +1131,14 @@ PyObject_RichCompareBool(PyObject *v, PyObject *w, int op)
     res = PyObject_RichCompare(v, w, op);
     if (res == NULL)
         return -1;
-    if (PyBool_Check(res))
+    if (PyBool_Check(res)) {
         ok = (res == Py_True);
-    else
+        assert(_Py_IsImmortal(res));
+    }
+    else {
         ok = PyObject_IsTrue(res);
-    Py_DECREF(res);
+        Py_DECREF(res);
+    }
     return ok;
 }