bpo-44563: Fix error handling in tee.fromiterable() (GH-27020)

In debug build failed tee.fromiterable() corrupted the linked list of all GC objects.
This commit is contained in:
Serhiy Storchaka 2021-07-06 01:19:35 +03:00 committed by GitHub
parent 17f94e2888
commit f64de53ff0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 9 deletions

View File

@ -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;
}