Skip to content

Commit 324b932

Browse files
bpo-44563: Fix error handling in tee.fromiterable() (GH-27020) (GH-27042)
In debug build failed tee.fromiterable() corrupted the linked list of all GC objects. (cherry picked from commit f64de53) Co-authored-by: Serhiy Storchaka <[email protected]>
1 parent 51a29c4 commit 324b932

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
@@ -729,7 +729,7 @@ static PyObject *
729729
tee_fromiterable(PyObject *iterable)
730730
{
731731
teeobject *to;
732-
PyObject *it = NULL;
732+
PyObject *it;
733733

734734
it = PyObject_GetIter(iterable);
735735
if (it == NULL)
@@ -739,21 +739,22 @@ tee_fromiterable(PyObject *iterable)
739739
goto done;
740740
}
741741

742-
to = PyObject_GC_New(teeobject, &tee_type);
743-
if (to == NULL)
744-
goto done;
745-
to->dataobj = (teedataobject *)teedataobject_newinternal(it);
746-
if (!to->dataobj) {
747-
PyObject_GC_Del(to);
742+
PyObject *dataobj = teedataobject_newinternal(it);
743+
if (!dataobj) {
748744
to = NULL;
749745
goto done;
750746
}
751-
747+
to = PyObject_GC_New(teeobject, &tee_type);
748+
if (to == NULL) {
749+
Py_DECREF(dataobj);
750+
goto done;
751+
}
752+
to->dataobj = (teedataobject *)dataobj;
752753
to->index = 0;
753754
to->weakreflist = NULL;
754755
PyObject_GC_Track(to);
755756
done:
756-
Py_XDECREF(it);
757+
Py_DECREF(it);
757758
return (PyObject *)to;
758759
}
759760

0 commit comments

Comments
 (0)