]> granicus.if.org Git - python/commitdiff
bpo-31579: Fixed a possible leak in enumerate() with large indices. (#3753)
authorSerhiy Storchaka <storchaka@gmail.com>
Tue, 26 Sep 2017 05:14:58 +0000 (08:14 +0300)
committerGitHub <noreply@github.com>
Tue, 26 Sep 2017 05:14:58 +0000 (08:14 +0300)
Objects/enumobject.c

index 154d901e86d1198626aa778689efe886c381e657..4d0af14008b9390ef13c0555a1fcf437b8d285bc 100644 (file)
@@ -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) {