From a7b0c12152e6268bb09b462f2a0fe52178ee6065 Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Mon, 16 Feb 2009 21:23:04 +0000 Subject: PyList_Append() can fail --- Modules/itertoolsmodule.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Modules/itertoolsmodule.c b/Modules/itertoolsmodule.c index f42232d..fefcbfb 100644 --- a/Modules/itertoolsmodule.c +++ b/Modules/itertoolsmodule.c @@ -745,8 +745,10 @@ cycle_next(cycleobject *lz) while (1) { item = PyIter_Next(lz->it); if (item != NULL) { - if (!lz->firstpass) - PyList_Append(lz->saved, item); + if (!lz->firstpass && PyList_Append(lz->saved, item)) { + Py_DECREF(item); + return NULL; + } return item; } if (PyErr_Occurred()) { -- cgit v0.12