summaryrefslogtreecommitdiffstats
path: root/Objects/rangeobject.c
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2009-11-16 00:34:25 (GMT)
committerBenjamin Peterson <benjamin@python.org>2009-11-16 00:34:25 (GMT)
commit36fbb730a72c0a00a2c2dc44d49b9b7af5a86174 (patch)
tree8a0974491dc19e492251a69df00b5d30fb29a3ad /Objects/rangeobject.c
parent91799ae3e11cc85798ffaa633369895f216c6c65 (diff)
downloadcpython-36fbb730a72c0a00a2c2dc44d49b9b7af5a86174.zip
cpython-36fbb730a72c0a00a2c2dc44d49b9b7af5a86174.tar.gz
cpython-36fbb730a72c0a00a2c2dc44d49b9b7af5a86174.tar.bz2
fix one visible and several possible refleaks in rangeobject.c
In some cases, the code was just reordered to allow for less decrefing.
Diffstat (limited to 'Objects/rangeobject.c')
-rw-r--r--Objects/rangeobject.c37
1 files changed, 17 insertions, 20 deletions
diff --git a/Objects/rangeobject.c b/Objects/rangeobject.c
index ec75c8f..cd148c6 100644
--- a/Objects/rangeobject.c
+++ b/Objects/rangeobject.c
@@ -533,6 +533,7 @@ int_range_iter(long start, long stop, long step)
it->step = step;
ulen = get_len_of_range(start, stop, step);
if (ulen > (unsigned long)LONG_MAX) {
+ Py_DECREF(it);
PyErr_SetString(PyExc_OverflowError,
"range too large to represent as a range_iterator");
return NULL;
@@ -584,16 +585,14 @@ longrangeiter_next(longrangeiterobject *r)
if (!one)
return NULL;
- product = PyNumber_Multiply(r->index, r->step);
- if (!product) {
- Py_DECREF(one);
- return NULL;
- }
-
new_index = PyNumber_Add(r->index, one);
Py_DECREF(one);
- if (!new_index) {
- Py_DECREF(product);
+ if (!new_index)
+ return NULL;
+
+ product = PyNumber_Multiply(r->index, r->step);
+ if (!product) {
+ Py_DECREF(new_index);
return NULL;
}
@@ -603,6 +602,9 @@ longrangeiter_next(longrangeiterobject *r)
Py_DECREF(r->index);
r->index = new_index;
}
+ else {
+ Py_DECREF(new_index);
+ }
return result;
}
@@ -781,6 +783,9 @@ long_range:
if (!len)
goto create_failure;
+ /* Steal reference to len. */
+ it->len = len;
+
one = PyLong_FromLong(1);
if (!one)
goto create_failure;
@@ -802,24 +807,16 @@ long_range:
goto create_failure;
it->step = PyNumber_Negative(range->step);
- if (!it->step) {
- Py_DECREF(it->start);
+ if (!it->step)
goto create_failure;
- }
-
- /* Steal reference to len. */
- it->len = len;
it->index = PyLong_FromLong(0);
- if (!it->index) {
- Py_DECREF(it);
- return NULL;
- }
+ if (!it->index)
+ goto create_failure;
return (PyObject *)it;
create_failure:
- Py_XDECREF(len);
- PyObject_Del(it);
+ Py_DECREF(it);
return NULL;
}