[Python-checkins] [2.7] bpo-31579: Fixed a possible leak in enumerate() with large indices. (GH-3753). (#3761)

Serhiy Storchaka webhook-mailer at python.org
Tue Sep 26 02:11:31 EDT 2017


https://github.com/python/cpython/commit/19eb87d857f6d1bad1a3619d9d7534820f82e5f2
commit: 19eb87d857f6d1bad1a3619d9d7534820f82e5f2
branch: 2.7
author: Serhiy Storchaka <storchaka at gmail.com>
committer: GitHub <noreply at github.com>
date: 2017年09月26日T09:11:27+03:00
summary:
[2.7] bpo-31579: Fixed a possible leak in enumerate() with large indices. (GH-3753). (#3761)
(cherry picked from commit 0e950dd22b075b4809c84afda8aede02b76ac0fa)
files:
M Objects/enumobject.c
diff --git a/Objects/enumobject.c b/Objects/enumobject.c
index 1ef381f3914..8f86a5b8de3 100644
--- a/Objects/enumobject.c
+++ b/Objects/enumobject.c
@@ -87,19 +87,25 @@ enum_next_long(enumobject *en, PyObject* next_item)
 
 if (en->en_longindex == NULL) {
 en->en_longindex = PyInt_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 = PyInt_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) {


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /