summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2021-07-05 22:19:35 (GMT)
committerGitHub <noreply@github.com>2021-07-05 22:19:35 (GMT)
commitf64de53ff01e734d48d1d42195443d7d1646f220 (patch)
tree7be6dfc9d95a79a432c6302b7260ec2f86b7b5de /Modules
parent17f94e28882e1e2b331ace93f42e8615383dee59 (diff)
downloadcpython-f64de53ff01e734d48d1d42195443d7d1646f220.zip
cpython-f64de53ff01e734d48d1d42195443d7d1646f220.tar.gz
cpython-f64de53ff01e734d48d1d42195443d7d1646f220.tar.bz2
bpo-44563: Fix error handling in tee.fromiterable() (GH-27020)
In debug build failed tee.fromiterable() corrupted the linked list of all GC objects.
Diffstat (limited to 'Modules')
-rw-r--r--Modules/itertoolsmodule.c19
1 files changed, 10 insertions, 9 deletions
diff --git a/Modules/itertoolsmodule.c b/Modules/itertoolsmodule.c
index 293735a..643f47b 100644
--- a/Modules/itertoolsmodule.c
+++ b/Modules/itertoolsmodule.c
@@ -863,7 +863,7 @@ static PyObject *
tee_fromiterable(PyObject *iterable)
{
teeobject *to;
- PyObject *it = NULL;
+ PyObject *it;
it = PyObject_GetIter(iterable);
if (it == NULL)
@@ -873,21 +873,22 @@ tee_fromiterable(PyObject *iterable)
goto done;
}
- to = PyObject_GC_New(teeobject, &tee_type);
- if (to == NULL)
- goto done;
- to->dataobj = (teedataobject *)teedataobject_newinternal(it);
- if (!to->dataobj) {
- PyObject_GC_Del(to);
+ PyObject *dataobj = teedataobject_newinternal(it);
+ if (!dataobj) {
to = NULL;
goto done;
}
-
+ to = PyObject_GC_New(teeobject, &tee_type);
+ if (to == NULL) {
+ Py_DECREF(dataobj);
+ goto done;
+ }
+ to->dataobj = (teedataobject *)dataobj;
to->index = 0;
to->weakreflist = NULL;
PyObject_GC_Track(to);
done:
- Py_XDECREF(it);
+ Py_DECREF(it);
return (PyObject *)to;
}