]> granicus.if.org Git - python/commitdiff
[3.6] bpo-31579: Fixed a possible leak in enumerate() with large indices. (GH-3753...
authorSerhiy Storchaka <storchaka@gmail.com>
Tue, 26 Sep 2017 06:11:34 +0000 (09:11 +0300)
committerGitHub <noreply@github.com>
Tue, 26 Sep 2017 06:11:34 +0000 (09:11 +0300)
(cherry picked from commit 0e950dd22b075b4809c84afda8aede02b76ac0fa)

Objects/enumobject.c

index dae166d5adf4687f1b68de68280ad0b9748fccf2..b92b8987fbb0cdc690847b20e868f9e813b5020d 100644 (file)
@@ -87,19 +87,25 @@ 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;
+        }
     }
     if (one == NULL) {
         one = PyLong_FromLong(1);
-        if (one == NULL)
+        if (one == NULL) {
+            Py_DECREF(next_item);
             return NULL;
+        }
     }
     next_index = en->en_longindex;
     assert(next_index != NULL);
     stepped_up = PyNumber_Add(next_index, 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) {