[Python-checkins] bpo-44563: Fix error handling in tee.fromiterable() (GH-27020) (GH-27041)

pablogsal webhook-mailer at python.org
Mon Jul 5 18:35:02 EDT 2021


https://github.com/python/cpython/commit/645e527298b1f24625783338076330037d860162
commit: 645e527298b1f24625783338076330037d860162
branch: 3.10
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: pablogsal <Pablogsal at gmail.com>
date: 2021-07-05T23:34:53+01:00
summary:

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

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

Co-authored-by: Serhiy Storchaka <storchaka at gmail.com>

Co-authored-by: Serhiy Storchaka <storchaka at gmail.com>

files:
M Modules/itertoolsmodule.c

diff --git a/Modules/itertoolsmodule.c b/Modules/itertoolsmodule.c
index 293735a886428..643f47b045046 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;
 }
 



More information about the Python-checkins mailing list