summaryrefslogtreecommitdiffstats
path: root/Objects/enumobject.c
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2017-09-26 05:14:58 (GMT)
committerGitHub <noreply@github.com>2017-09-26 05:14:58 (GMT)
commit0e950dd22b075b4809c84afda8aede02b76ac0fa (patch)
treee15d01835bf14fa38fcc733bb9b9dd7f3c3e4ba3 /Objects/enumobject.c
parent4a2d00cb4525fcb3209f04531472ba6a359ed418 (diff)
downloadcpython-0e950dd22b075b4809c84afda8aede02b76ac0fa.zip
cpython-0e950dd22b075b4809c84afda8aede02b76ac0fa.tar.gz
cpython-0e950dd22b075b4809c84afda8aede02b76ac0fa.tar.bz2
bpo-31579: Fixed a possible leak in enumerate() with large indices. (#3753)
Diffstat (limited to 'Objects/enumobject.c')
-rw-r--r--Objects/enumobject.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/Objects/enumobject.c b/Objects/enumobject.c
index 154d901..4d0af14 100644
--- a/Objects/enumobject.c
+++ b/Objects/enumobject.c
@@ -108,14 +108,18 @@ enum_next_long(enumobject *en, PyObject* next_item)
if (en->en_longindex == NULL) {
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;
+ }
}
next_index = en->en_longindex;
assert(next_index != NULL);
stepped_up = PyNumber_Add(next_index, _PyLong_One);
- if (stepped_up == NULL)
+ if (stepped_up == NULL) {
+ Py_DECREF(next_item);
return NULL;
+ }
en->en_longindex = stepped_up;
if (result->ob_refcnt == 1) {