diff options
author | Neal Norwitz <nnorwitz@gmail.com> | 2006-07-23 07:59:00 (GMT) |
---|---|---|
committer | Neal Norwitz <nnorwitz@gmail.com> | 2006-07-23 07:59:00 (GMT) |
commit | 9029b5f28934f78c5c13c62e8565f468955eb4df (patch) | |
tree | 47f6bacb7b987f04a562abcc9ac9839c004d6342 /Modules | |
parent | 98a96004f97c1810831f74fc68ec2ccc4ec607c4 (diff) | |
download | cpython-9029b5f28934f78c5c13c62e8565f468955eb4df.zip cpython-9029b5f28934f78c5c13c62e8565f468955eb4df.tar.gz cpython-9029b5f28934f78c5c13c62e8565f468955eb4df.tar.bz2 |
nextlink can be NULL if teedataobject_new fails, so use XINCREF.
Ensure that dataobj is never NULL.
Reported by Klocwork #102
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/itertoolsmodule.c | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/Modules/itertoolsmodule.c b/Modules/itertoolsmodule.c index 86b1bbf..d913890 100644 --- a/Modules/itertoolsmodule.c +++ b/Modules/itertoolsmodule.c @@ -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); |