]> granicus.if.org Git - python/commitdiff
nextlink can be NULL if teedataobject_new fails, so use XINCREF.
authorNeal Norwitz <nnorwitz@gmail.com>
Sun, 23 Jul 2006 07:59:00 +0000 (07:59 +0000)
committerNeal Norwitz <nnorwitz@gmail.com>
Sun, 23 Jul 2006 07:59:00 +0000 (07:59 +0000)
Ensure that dataobj is never NULL.

Reported by Klocwork #102

Modules/itertoolsmodule.c

index 86b1bbfb3404bd83db5e4d59ba35580017de59c0..d91389033ff4ec719105716ef4dafc8b0dbbd16d 100644 (file)
@@ -357,7 +357,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;
 }
 
@@ -468,7 +468,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;
        }
@@ -522,6 +522,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;
        PyObject_GC_Track(to);