Skip to content

Commit d6a3562

Browse files
[3.6] bpo-31579: Fixed a possible leak in enumerate() with large indices. (GH-3753). (#3760)
(cherry picked from commit 0e950dd)
1 parent 26b940f commit d6a3562

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

Objects/enumobject.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,19 +87,25 @@ enum_next_long(enumobject *en, PyObject* next_item)
8787

8888
if (en->en_longindex == NULL) {
8989
en->en_longindex = PyLong_FromSsize_t(PY_SSIZE_T_MAX);
90-
if (en->en_longindex == NULL)
90+
if (en->en_longindex == NULL) {
91+
Py_DECREF(next_item);
9192
return NULL;
93+
}
9294
}
9395
if (one == NULL) {
9496
one = PyLong_FromLong(1);
95-
if (one == NULL)
97+
if (one == NULL) {
98+
Py_DECREF(next_item);
9699
return NULL;
100+
}
97101
}
98102
next_index = en->en_longindex;
99103
assert(next_index != NULL);
100104
stepped_up = PyNumber_Add(next_index, one);
101-
if (stepped_up == NULL)
105+
if (stepped_up == NULL) {
106+
Py_DECREF(next_item);
102107
return NULL;
108+
}
103109
en->en_longindex = stepped_up;
104110

105111
if (result->ob_refcnt == 1) {

0 commit comments

Comments
 (0)