From: Jelle Zijlstra Date: Sun, 26 Feb 2023 00:38:00 +0000 (-0800) Subject: [3.10] gh-101765: Fix refcount issues in list and unicode pickling (GH-102265) (... X-Git-Tag: v3.10.11~75 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=6fa6c2a470e86057a253f9a159c2cbcdcc184112;p=thirdparty%2FPython%2Fcpython.git [3.10] gh-101765: Fix refcount issues in list and unicode pickling (GH-102265) (#102269) (cherry picked from commit d71edbd1b7437706519a9786211597d95934331a) --- diff --git a/Objects/listobject.c b/Objects/listobject.c index f46d5e45cc5e..2143475d9351 100644 --- a/Objects/listobject.c +++ b/Objects/listobject.c @@ -3412,16 +3412,24 @@ listiter_reduce_general(void *_it, int forward) /* the objects are not the same, index is of different types! */ if (forward) { PyObject *iter = _PyEval_GetBuiltinId(&PyId_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_GetBuiltinId(&PyId_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 5a1865fb3493..16225ed8ac34 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -16080,8 +16080,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); } }