[Python-checkins] [3.11] gh-101765: Fix refcount issues in list and unicode pickling (GH-102265) (#102268)

JelleZijlstra webhook-mailer at python.org
Sat Feb 25 19:38:25 EST 2023


https://github.com/python/cpython/commit/b36c49899b04fff0768364c17e14facf27975336
commit: b36c49899b04fff0768364c17e14facf27975336
branch: 3.11
author: Jelle Zijlstra <jelle.zijlstra at gmail.com>
committer: JelleZijlstra <jelle.zijlstra at gmail.com>
date: 2023-02-25T16:38:19-08:00
summary:

[3.11] gh-101765: Fix refcount issues in list and unicode pickling (GH-102265) (#102268)

(cherry picked from commit d71edbd1b7437706519a9786211597d95934331a)

files:
M Objects/listobject.c
M Objects/unicodeobject.c

diff --git a/Objects/listobject.c b/Objects/listobject.c
index 0b20829a280a..0d4e4741fdf3 100644
--- a/Objects/listobject.c
+++ b/Objects/listobject.c
@@ -3459,16 +3459,24 @@ listiter_reduce_general(void *_it, int forward)
     /* the objects are not the same, index is of different types! */
     if (forward) {
         PyObject *iter = _PyEval_GetBuiltin(&_Py_ID(iter));
+        if (!iter) {
+            return NULL;
+        }
         listiterobject *it = (listiterobject *)_it;
         if (it->it_seq) {
             return Py_BuildValue("N(O)n", iter, it->it_seq, it->it_index);
         }
+        Py_DECREF(iter);
     } else {
         PyObject *reversed = _PyEval_GetBuiltin(&_Py_ID(reversed));
+        if (!reversed) {
+            return NULL;
+        }
         listreviterobject *it = (listreviterobject *)_it;
         if (it->it_seq) {
             return Py_BuildValue("N(O)n", reversed, it->it_seq, it->it_index);
         }
+        Py_DECREF(reversed);
     }
     /* empty iterator, create an empty list */
     list = PyList_New(0);
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
index 02343d7c9326..9b8296ca6bb0 100644
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -15767,8 +15767,10 @@ unicodeiter_reduce(unicodeiterobject *it, PyObject *Py_UNUSED(ignored))
         return Py_BuildValue("N(O)n", iter, it->it_seq, it->it_index);
     } else {
         PyObject *u = (PyObject *)_PyUnicode_New(0);
-        if (u == NULL)
+        if (u == NULL) {
+            Py_DECREF(iter);
             return NULL;
+        }
         return Py_BuildValue("N(N)", iter, u);
     }
 }



More information about the Python-checkins mailing list