]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-101765: Fix refcount issues in list and unicode pickling (#102265)
authorJelle Zijlstra <jelle.zijlstra@gmail.com>
Sun, 26 Feb 2023 00:01:58 +0000 (16:01 -0800)
committerGitHub <noreply@github.com>
Sun, 26 Feb 2023 00:01:58 +0000 (16:01 -0800)
Followup from #101769.

Objects/listobject.c
Objects/unicodeobject.c

index 494b40178f9f277a8dea6484209049865279051c..1a210e77d55c290f1e1330f1f623e5dce253732b 100644 (file)
@@ -3451,16 +3451,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;
+        }
         _PyListIterObject *it = (_PyListIterObject *)_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);
index 6403e359c70714ef80c7e234ca838053a58f194a..2f4c3d3793efd6f9e3db43f63803c081810949bf 100644 (file)
@@ -14794,8 +14794,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 = unicode_new_empty();
-        if (u == NULL)
+        if (u == NULL) {
+            Py_DECREF(iter);
             return NULL;
+        }
         return Py_BuildValue("N(N)", iter, u);
     }
 }