Skip to content

Commit fca504e

Browse files
committed
[3.10] pythongh-101765: Fix refcount issues in list and unicode pickling (pythonGH-102265)
Followup from pythonGH-101769.. (cherry picked from commit d71edbd) Co-authored-by: Jelle Zijlstra <[email protected]>
1 parent 4667c4d commit fca504e

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

Objects/listobject.c

+8
Original file line numberDiff line numberDiff line change
@@ -3412,16 +3412,24 @@ listiter_reduce_general(void *_it, int forward)
34123412
/* the objects are not the same, index is of different types! */
34133413
if (forward) {
34143414
PyObject *iter = _PyEval_GetBuiltinId(&PyId_iter);
3415+
if (!iter) {
3416+
return NULL;
3417+
}
34153418
listiterobject *it = (listiterobject *)_it;
34163419
if (it->it_seq) {
34173420
return Py_BuildValue("N(O)n", iter, it->it_seq, it->it_index);
34183421
}
3422+
Py_DECREF(iter);
34193423
} else {
34203424
PyObject *reversed = _PyEval_GetBuiltinId(&PyId_reversed);
3425+
if (!reversed) {
3426+
return NULL;
3427+
}
34213428
listreviterobject *it = (listreviterobject *)_it;
34223429
if (it->it_seq) {
34233430
return Py_BuildValue("N(O)n", reversed, it->it_seq, it->it_index);
34243431
}
3432+
Py_DECREF(reversed);
34253433
}
34263434
/* empty iterator, create an empty list */
34273435
list = PyList_New(0);

Objects/unicodeobject.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -16080,8 +16080,10 @@ unicodeiter_reduce(unicodeiterobject *it, PyObject *Py_UNUSED(ignored))
1608016080
return Py_BuildValue("N(O)n", iter, it->it_seq, it->it_index);
1608116081
} else {
1608216082
PyObject *u = (PyObject *)_PyUnicode_New(0);
16083-
if (u == NULL)
16083+
if (u == NULL) {
16084+
Py_DECREF(iter);
1608416085
return NULL;
16086+
}
1608516087
return Py_BuildValue("N(N)", iter, u);
1608616088
}
1608716089
}

0 commit comments

Comments
 (0)