]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[Backport r50782 | neal.norwitz]
authorAndrew M. Kuchling <amk@amk.ca>
Tue, 3 Oct 2006 19:22:30 +0000 (19:22 +0000)
committerAndrew M. Kuchling <amk@amk.ca>
Tue, 3 Oct 2006 19:22:30 +0000 (19:22 +0000)
nextlink can be NULL if teedataobject_new fails, so use XINCREF.
Ensure that dataobj is never NULL.

Reported by Klocwork #102

Modules/itertoolsmodule.c

index 39af2ea931ed304aa4088ad87a351f310c0681db..97a6858c479fa7c15330a5c4119694ca89d46e8d 100644 (file)
@@ -356,7 +356,7 @@ teedataobject_jumplink(teedataobject *tdo)
 {
        if (tdo->nextlink == NULL)
                tdo->nextlink = teedataobject_new(tdo->it);
-       Py_INCREF(tdo->nextlink);
+       Py_XINCREF(tdo->nextlink);
        return tdo->nextlink;
 }
 
@@ -432,7 +432,7 @@ tee_next(teeobject *to)
 
        if (to->index >= LINKCELLS) {
                link = teedataobject_jumplink(to->dataobj);
-               Py_XDECREF(to->dataobj);
+               Py_DECREF(to->dataobj);
                to->dataobj = (teedataobject *)link;
                to->index = 0;
        }
@@ -478,6 +478,12 @@ tee_fromiterable(PyObject *iterable)
        if (to == NULL) 
                goto done;
        to->dataobj = (teedataobject *)teedataobject_new(it);
+       if (!to->dataobj) {
+               PyObject_GC_Del(to);
+               to = NULL;
+               goto done;
+       }
+
        to->index = 0;
        to->weakreflist = NULL;
 done: