diff options
author | Guido van Rossum <guido@python.org> | 2007-05-08 15:18:31 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2007-05-08 15:18:31 (GMT) |
commit | 317e7749656548f629cb9a1c0a01e31b518ff2ff (patch) | |
tree | 91a4b0b59c4b7c191af3ed178f44d8939044a2c6 /Objects/rangeobject.c | |
parent | 617dbc4d643749804057f8dc7c52df702e40fe7a (diff) | |
download | cpython-317e7749656548f629cb9a1c0a01e31b518ff2ff.zip cpython-317e7749656548f629cb9a1c0a01e31b518ff2ff.tar.gz cpython-317e7749656548f629cb9a1c0a01e31b518ff2ff.tar.bz2 |
Merged revisions 55180-55183 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/p3yk
........
r55182 | neal.norwitz | 2007-05-07 23:03:06 -0700 (Mon, 07 May 2007) | 1 line
Fix refleaks when using range with large values
........
Diffstat (limited to 'Objects/rangeobject.c')
-rw-r--r-- | Objects/rangeobject.c | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/Objects/rangeobject.c b/Objects/rangeobject.c index f38935b..8d71a90 100644 --- a/Objects/rangeobject.c +++ b/Objects/rangeobject.c @@ -386,6 +386,7 @@ longrangeiter_len(longrangeiterobject *r, PyObject *no_args) { return PyNumber_Subtract(r->len, r->index); } + static PyObject *rangeiter_new(PyTypeObject *, PyObject *args, PyObject *kw); PyDoc_STRVAR(length_hint_doc, @@ -510,9 +511,9 @@ static void longrangeiter_dealloc(longrangeiterobject *r) { Py_XDECREF(r->index); - Py_DECREF(r->start); - Py_DECREF(r->step); - Py_DECREF(r->len); + Py_XDECREF(r->start); + Py_XDECREF(r->step); + Py_XDECREF(r->len); } static PyObject * @@ -601,7 +602,15 @@ range_iter(PyObject *seq) it = PyObject_New(longrangeiterobject, &Pylongrangeiter_Type); if (it == NULL) return NULL; + + /* Do all initialization here, so we can DECREF on failure. */ it->start = r->start; + it->step = r->step; + Py_INCREF(it->start); + Py_INCREF(it->step); + + it->len = it->index = NULL; + /* Calculate length: (r->stop - r->start) / r->step */ tmp = PyNumber_Subtract(r->stop, r->start); if (!tmp) @@ -611,18 +620,14 @@ range_iter(PyObject *seq) if (!len) goto create_failure; it->len = len; - it->step = r->step; it->index = PyLong_FromLong(0); if (!it->index) goto create_failure; - Py_INCREF(it->start); - Py_INCREF(it->step); - Py_INCREF(it->len); return (PyObject *)it; create_failure: - PyObject_Del(it); + Py_DECREF(it); return NULL; } |