Skip to content

Commit 0e950dd

Browse files
bpo-31579: Fixed a possible leak in enumerate() with large indices. (#3753)
1 parent 4a2d00c commit 0e950dd

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

Objects/enumobject.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,14 +108,18 @@ enum_next_long(enumobject *en, PyObject* next_item)
108108

109109
if (en->en_longindex == NULL) {
110110
en->en_longindex = PyLong_FromSsize_t(PY_SSIZE_T_MAX);
111-
if (en->en_longindex == NULL)
111+
if (en->en_longindex == NULL) {
112+
Py_DECREF(next_item);
112113
return NULL;
114+
}
113115
}
114116
next_index = en->en_longindex;
115117
assert(next_index != NULL);
116118
stepped_up = PyNumber_Add(next_index, _PyLong_One);
117-
if (stepped_up == NULL)
119+
if (stepped_up == NULL) {
120+
Py_DECREF(next_item);
118121
return NULL;
122+
}
119123
en->en_longindex = stepped_up;
120124

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

0 commit comments

Comments
 (0)