summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJelle Zijlstra <jelle.zijlstra@gmail.com>2023-02-26 00:38:00 (GMT)
committerGitHub <noreply@github.com>2023-02-26 00:38:00 (GMT)
commit6fa6c2a470e86057a253f9a159c2cbcdcc184112 (patch)
treea017224b3788c8622cecd69122fbdb0ae493a404
parent4667c4dcdefb810bcde045db651c585c3bbc36bb (diff)
downloadcpython-6fa6c2a470e86057a253f9a159c2cbcdcc184112.zip
cpython-6fa6c2a470e86057a253f9a159c2cbcdcc184112.tar.gz
cpython-6fa6c2a470e86057a253f9a159c2cbcdcc184112.tar.bz2
[3.10] gh-101765: Fix refcount issues in list and unicode pickling (GH-102265) (#102269)
(cherry picked from commit d71edbd1b7437706519a9786211597d95934331a)
-rw-r--r--Objects/listobject.c8
-rw-r--r--Objects/unicodeobject.c4
2 files changed, 11 insertions, 1 deletions
diff --git a/Objects/listobject.c b/Objects/listobject.c
index f46d5e4..2143475 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 5a1865f..16225ed 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);
}
}