From: Pieter Eendebak Date: Fri, 27 Jun 2025 09:01:51 +0000 (+0200) Subject: gh-136017: avoid decref in rich compare for bool objects (#136018) X-Git-Tag: v3.15.0a1~1163 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e23518fa96583d0190d457adb807b19545df26cf;p=thirdparty%2FPython%2Fcpython.git gh-136017: avoid decref in rich compare for bool objects (#136018) --- diff --git a/Objects/object.c b/Objects/object.c index 4d60128b092c..1223983753ac 100644 --- a/Objects/object.c +++ b/Objects/object.c @@ -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; }