Skip to content

Commit f64de53

Browse files
bpo-44563: Fix error handling in tee.fromiterable() (GH-27020)
In debug build failed tee.fromiterable() corrupted the linked list of all GC objects.
1 parent 17f94e2 commit f64de53

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

Modules/itertoolsmodule.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -863,7 +863,7 @@ static PyObject *
863863
tee_fromiterable(PyObject *iterable)
864864
{
865865
teeobject *to;
866-
PyObject *it = NULL;
866+
PyObject *it;
867867

868868
it = PyObject_GetIter(iterable);
869869
if (it == NULL)
@@ -873,21 +873,22 @@ tee_fromiterable(PyObject *iterable)
873873
goto done;
874874
}
875875

876-
to = PyObject_GC_New(teeobject, &tee_type);
877-
if (to == NULL)
878-
goto done;
879-
to->dataobj = (teedataobject *)teedataobject_newinternal(it);
880-
if (!to->dataobj) {
881-
PyObject_GC_Del(to);
876+
PyObject *dataobj = teedataobject_newinternal(it);
877+
if (!dataobj) {
882878
to = NULL;
883879
goto done;
884880
}
885-
881+
to = PyObject_GC_New(teeobject, &tee_type);
882+
if (to == NULL) {
883+
Py_DECREF(dataobj);
884+
goto done;
885+
}
886+
to->dataobj = (teedataobject *)dataobj;
886887
to->index = 0;
887888
to->weakreflist = NULL;
888889
PyObject_GC_Track(to);
889890
done:
890-
Py_XDECREF(it);
891+
Py_DECREF(it);
891892
return (PyObject *)to;
892893
}
893894

0 commit comments

Comments
 (0)