diff options
author | Jelle Zijlstra <jelle.zijlstra@gmail.com> | 2023-02-26 00:01:58 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-02-26 00:01:58 (GMT) |
commit | d71edbd1b7437706519a9786211597d95934331a (patch) | |
tree | 196aeafec3fbe879f97d445808683dbeb725b940 | |
parent | a498de4c0ef9e264cab3320afbc4d38df6394800 (diff) | |
download | cpython-d71edbd1b7437706519a9786211597d95934331a.zip cpython-d71edbd1b7437706519a9786211597d95934331a.tar.gz cpython-d71edbd1b7437706519a9786211597d95934331a.tar.bz2 |
gh-101765: Fix refcount issues in list and unicode pickling (#102265)
Followup from #101769.
-rw-r--r-- | Objects/listobject.c | 8 | ||||
-rw-r--r-- | Objects/unicodeobject.c | 4 |
2 files changed, 11 insertions, 1 deletions
diff --git a/Objects/listobject.c b/Objects/listobject.c index 494b401..1a210e7 100644 --- a/Objects/listobject.c +++ b/Objects/listobject.c @@ -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); diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index 6403e35..2f4c3d3 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -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); } } |