[Python-3000-checkins] r55182 - python/branches/p3yk/Objects/rangeobject.c
neal.norwitz
python-3000-checkins at python.org
Tue May 8 08:03:08 CEST 2007
Author: neal.norwitz
Date: Tue May 8 08:03:06 2007
New Revision: 55182
Modified:
python/branches/p3yk/Objects/rangeobject.c
Log:
Fix refleaks when using range with large values
Modified: python/branches/p3yk/Objects/rangeobject.c
==============================================================================
--- python/branches/p3yk/Objects/rangeobject.c (original)
+++ python/branches/p3yk/Objects/rangeobject.c Tue May 8 08:03:06 2007
@@ -386,6 +386,7 @@
{
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 @@
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 @@
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 @@
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;
}
More information about the Python-3000-checkins
mailing list