Skip to content

Commit

Permalink
bpo-44563: Fix error handling in tee.fromiterable() (GH-27020) (GH-27042
Browse files Browse the repository at this point in the history
)

In debug build failed tee.fromiterable() corrupted the linked list of all GC objects.
(cherry picked from commit f64de53)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
  • Loading branch information
miss-islington and serhiy-storchaka committed Jul 5, 2021
1 parent 51a29c4 commit 324b932
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions Modules/itertoolsmodule.c
Expand Up @@ -729,7 +729,7 @@ static PyObject *
tee_fromiterable(PyObject *iterable)
{
teeobject *to;
PyObject *it = NULL;
PyObject *it;

it = PyObject_GetIter(iterable);
if (it == NULL)
Expand All @@ -739,21 +739,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;
}

Expand Down

0 comments on commit 324b932

Please sign in to comment.