Mercurial > cpython-lru_cache-weakref
diff Modules/itertoolsmodule.c @ 81703:62f2d3f6015e 2.7
Issue #13454: Fix a crash when deleting an iterator created by itertools.tee()
if all other iterators were very advanced before.
| author | Serhiy Storchaka <storchaka@gmail.com> |
|---|---|
| date | Fri, 25 Jan 2013 13:31:05 +0200 |
| parents | ba1c48f8b571 |
| children | d17d10c84d27 |
line wrap: on
line diff
--- a/Modules/itertoolsmodule.c Fri Jan 25 10:03:12 2013 +0200 +++ b/Modules/itertoolsmodule.c Fri Jan 25 13:31:05 2013 +0200 @@ -401,14 +401,31 @@ return 0; } +static void +teedataobject_safe_decref(PyObject *obj) +{ + while (obj && Py_TYPE(obj) == &teedataobject_type && + Py_REFCNT(obj) == 1) { + PyObject *nextlink = ((teedataobject *)obj)->nextlink; + ((teedataobject *)obj)->nextlink = NULL; + Py_DECREF(obj); + obj = nextlink; + } + Py_XDECREF(obj); +} + static int teedataobject_clear(teedataobject *tdo) { int i; + PyObject *tmp; + Py_CLEAR(tdo->it); for (i=0 ; i<tdo->numread ; i++) Py_CLEAR(tdo->values[i]); - Py_CLEAR(tdo->nextlink); + tmp = tdo->nextlink; + tdo->nextlink = NULL; + teedataobject_safe_decref(tmp); return 0; } @@ -475,6 +492,8 @@ if (to->index >= LINKCELLS) { link = teedataobject_jumplink(to->dataobj); + if (link == NULL) + return NULL; Py_DECREF(to->dataobj); to->dataobj = (teedataobject *)link; to->index = 0;
