]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.11] gh-101765: Fix refcount issues in list and unicode pickling (GH-102265) (...
authorJelle Zijlstra <jelle.zijlstra@gmail.com>
Sun, 26 Feb 2023 00:38:19 +0000 (16:38 -0800)
committerGitHub <noreply@github.com>
Sun, 26 Feb 2023 00:38:19 +0000 (16:38 -0800)
(cherry picked from commit d71edbd1b7437706519a9786211597d95934331a)

Objects/listobject.c
Objects/unicodeobject.c

index 0b20829a280ac15d0a47ae7051fbae27215507ba..0d4e4741fdf3461181727ac3b733c0db7599508c 100644 (file)
@@ -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);
index 02343d7c93269b7deedf225cee5fd409d147f5ef..9b8296ca6bb0540aea72608917d9672044406d16 100644 (file)
@@ -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);
     }
 }