Mercurial > cpython-lru_cache-weakref
diff Modules/itertoolsmodule.c @ 39973:2f238a2cd189 2.4
[Backport r50782 | neal.norwitz]
nextlink can be NULL if teedataobject_new fails, so use XINCREF.
Ensure that dataobj is never NULL.
Reported by Klocwork #102
| author | Andrew M. Kuchling <amk@amk.ca> |
|---|---|
| date | Tue, 03 Oct 2006 19:22:30 +0000 |
| parents | 6fb46e87d5f9 |
| children |
line wrap: on
line diff
--- a/Modules/itertoolsmodule.c Tue Oct 03 19:18:33 2006 +0000 +++ b/Modules/itertoolsmodule.c Tue Oct 03 19:22:30 2006 +0000 @@ -356,7 +356,7 @@ { 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 @@ 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 @@ 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:
