https://github.com/python/cpython/commit/50f82d062b3b59a09d6b63648df22d46f7f2b010
commit: 50f82d062b3b59a09d6b63648df22d46f7f2b010
branch: main
author: Benedikt Johannes <[email protected]>
committer: kumaraditya303 <[email protected]>
date: 2026-03-10T22:03:56+05:30
summary:

gh-145044: avoid calling `Py_DECREF` in `unsafe_object_compare` on immortal 
objects (#145045)

files:
M Objects/listobject.c

diff --git a/Objects/listobject.c b/Objects/listobject.c
index 62d04ab150a77a..1fcedd3a28c91b 100644
--- a/Objects/listobject.c
+++ b/Objects/listobject.c
@@ -2795,11 +2795,12 @@ unsafe_object_compare(PyObject *v, PyObject *w, 
MergeState *ms)
 
     if (PyBool_Check(res_obj)) {
         res = (res_obj == Py_True);
+        assert(_Py_IsImmortal(res_obj));
     }
     else {
         res = PyObject_IsTrue(res_obj);
+        Py_DECREF(res_obj);
     }
-    Py_DECREF(res_obj);
 
     /* Note that we can't assert
      *     res == PyObject_RichCompareBool(v, w, Py_LT);

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]

Reply via email to