Skip to content

Commit

Permalink
[3.10] gh-101765: Fix refcount issues in list and unicode pickling (G…
Browse files Browse the repository at this point in the history
…H-102265) (#102269)

(cherry picked from commit d71edbd)
  • Loading branch information
JelleZijlstra authored Feb 26, 2023
1 parent 4667c4d commit 6fa6c2a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
8 changes: 8 additions & 0 deletions Objects/listobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 3 additions & 1 deletion Objects/unicodeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down

0 comments on commit 6fa6c2a

Please sign in to comment.