mirror of
https://github.com/python/cpython.git
synced 2025-09-30 20:31:52 +00:00
[3.6] bpo-31579: Fixed a possible leak in enumerate() with large indices. (GH-3753). (#3760)
(cherry picked from commit 0e950dd22b
)
This commit is contained in:
parent
26b940f762
commit
d6a356209a
1 changed files with 9 additions and 3 deletions
|
@ -87,19 +87,25 @@ enum_next_long(enumobject *en, PyObject* next_item)
|
||||||
|
|
||||||
if (en->en_longindex == NULL) {
|
if (en->en_longindex == NULL) {
|
||||||
en->en_longindex = PyLong_FromSsize_t(PY_SSIZE_T_MAX);
|
en->en_longindex = PyLong_FromSsize_t(PY_SSIZE_T_MAX);
|
||||||
if (en->en_longindex == NULL)
|
if (en->en_longindex == NULL) {
|
||||||
|
Py_DECREF(next_item);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (one == NULL) {
|
if (one == NULL) {
|
||||||
one = PyLong_FromLong(1);
|
one = PyLong_FromLong(1);
|
||||||
if (one == NULL)
|
if (one == NULL) {
|
||||||
|
Py_DECREF(next_item);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
next_index = en->en_longindex;
|
next_index = en->en_longindex;
|
||||||
assert(next_index != NULL);
|
assert(next_index != NULL);
|
||||||
stepped_up = PyNumber_Add(next_index, one);
|
stepped_up = PyNumber_Add(next_index, one);
|
||||||
if (stepped_up == NULL)
|
if (stepped_up == NULL) {
|
||||||
|
Py_DECREF(next_item);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
en->en_longindex = stepped_up;
|
en->en_longindex = stepped_up;
|
||||||
|
|
||||||
if (result->ob_refcnt == 1) {
|
if (result->ob_refcnt == 1) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue