mirror of https://github.com/python/cpython
fix one visible and several possible refleaks in rangeobject.c
In some cases, the code was just reordered to allow for less decrefing.
This commit is contained in:
parent
91799ae3e1
commit
36fbb730a7
|
@ -533,6 +533,7 @@ int_range_iter(long start, long stop, long step)
|
||||||
it->step = step;
|
it->step = step;
|
||||||
ulen = get_len_of_range(start, stop, step);
|
ulen = get_len_of_range(start, stop, step);
|
||||||
if (ulen > (unsigned long)LONG_MAX) {
|
if (ulen > (unsigned long)LONG_MAX) {
|
||||||
|
Py_DECREF(it);
|
||||||
PyErr_SetString(PyExc_OverflowError,
|
PyErr_SetString(PyExc_OverflowError,
|
||||||
"range too large to represent as a range_iterator");
|
"range too large to represent as a range_iterator");
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -584,16 +585,14 @@ longrangeiter_next(longrangeiterobject *r)
|
||||||
if (!one)
|
if (!one)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
product = PyNumber_Multiply(r->index, r->step);
|
|
||||||
if (!product) {
|
|
||||||
Py_DECREF(one);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
new_index = PyNumber_Add(r->index, one);
|
new_index = PyNumber_Add(r->index, one);
|
||||||
Py_DECREF(one);
|
Py_DECREF(one);
|
||||||
if (!new_index) {
|
if (!new_index)
|
||||||
Py_DECREF(product);
|
return NULL;
|
||||||
|
|
||||||
|
product = PyNumber_Multiply(r->index, r->step);
|
||||||
|
if (!product) {
|
||||||
|
Py_DECREF(new_index);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -603,6 +602,9 @@ longrangeiter_next(longrangeiterobject *r)
|
||||||
Py_DECREF(r->index);
|
Py_DECREF(r->index);
|
||||||
r->index = new_index;
|
r->index = new_index;
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
Py_DECREF(new_index);
|
||||||
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -781,6 +783,9 @@ long_range:
|
||||||
if (!len)
|
if (!len)
|
||||||
goto create_failure;
|
goto create_failure;
|
||||||
|
|
||||||
|
/* Steal reference to len. */
|
||||||
|
it->len = len;
|
||||||
|
|
||||||
one = PyLong_FromLong(1);
|
one = PyLong_FromLong(1);
|
||||||
if (!one)
|
if (!one)
|
||||||
goto create_failure;
|
goto create_failure;
|
||||||
|
@ -802,24 +807,16 @@ long_range:
|
||||||
goto create_failure;
|
goto create_failure;
|
||||||
|
|
||||||
it->step = PyNumber_Negative(range->step);
|
it->step = PyNumber_Negative(range->step);
|
||||||
if (!it->step) {
|
if (!it->step)
|
||||||
Py_DECREF(it->start);
|
|
||||||
goto create_failure;
|
goto create_failure;
|
||||||
}
|
|
||||||
|
|
||||||
/* Steal reference to len. */
|
|
||||||
it->len = len;
|
|
||||||
|
|
||||||
it->index = PyLong_FromLong(0);
|
it->index = PyLong_FromLong(0);
|
||||||
if (!it->index) {
|
if (!it->index)
|
||||||
Py_DECREF(it);
|
goto create_failure;
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (PyObject *)it;
|
return (PyObject *)it;
|
||||||
|
|
||||||
create_failure:
|
create_failure:
|
||||||
Py_XDECREF(len);
|
Py_DECREF(it);
|
||||||
PyObject_Del(it);
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue