mirror of
https://github.com/python/cpython.git
synced 2025-08-31 05:58:33 +00:00
gh-101765: Fix refcount issues in list and unicode pickling (#102265)
Followup from #101769.
This commit is contained in:
parent
a498de4c0e
commit
d71edbd1b7
2 changed files with 11 additions and 1 deletions
|
@ -3451,16 +3451,24 @@ listiter_reduce_general(void *_it, int forward)
|
||||||
/* the objects are not the same, index is of different types! */
|
/* the objects are not the same, index is of different types! */
|
||||||
if (forward) {
|
if (forward) {
|
||||||
PyObject *iter = _PyEval_GetBuiltin(&_Py_ID(iter));
|
PyObject *iter = _PyEval_GetBuiltin(&_Py_ID(iter));
|
||||||
|
if (!iter) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
_PyListIterObject *it = (_PyListIterObject *)_it;
|
_PyListIterObject *it = (_PyListIterObject *)_it;
|
||||||
if (it->it_seq) {
|
if (it->it_seq) {
|
||||||
return Py_BuildValue("N(O)n", iter, it->it_seq, it->it_index);
|
return Py_BuildValue("N(O)n", iter, it->it_seq, it->it_index);
|
||||||
}
|
}
|
||||||
|
Py_DECREF(iter);
|
||||||
} else {
|
} else {
|
||||||
PyObject *reversed = _PyEval_GetBuiltin(&_Py_ID(reversed));
|
PyObject *reversed = _PyEval_GetBuiltin(&_Py_ID(reversed));
|
||||||
|
if (!reversed) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
listreviterobject *it = (listreviterobject *)_it;
|
listreviterobject *it = (listreviterobject *)_it;
|
||||||
if (it->it_seq) {
|
if (it->it_seq) {
|
||||||
return Py_BuildValue("N(O)n", reversed, it->it_seq, it->it_index);
|
return Py_BuildValue("N(O)n", reversed, it->it_seq, it->it_index);
|
||||||
}
|
}
|
||||||
|
Py_DECREF(reversed);
|
||||||
}
|
}
|
||||||
/* empty iterator, create an empty list */
|
/* empty iterator, create an empty list */
|
||||||
list = PyList_New(0);
|
list = PyList_New(0);
|
||||||
|
|
|
@ -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);
|
return Py_BuildValue("N(O)n", iter, it->it_seq, it->it_index);
|
||||||
} else {
|
} else {
|
||||||
PyObject *u = unicode_new_empty();
|
PyObject *u = unicode_new_empty();
|
||||||
if (u == NULL)
|
if (u == NULL) {
|
||||||
|
Py_DECREF(iter);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
return Py_BuildValue("N(N)", iter, u);
|
return Py_BuildValue("N(N)", iter, u);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue