[Python-checkins] cpython (3.5): fix refleak when keys() fails

benjamin.peterson python-checkins at python.org
Thu Jun 4 21:34:56 CEST 2015


https://hg.python.org/cpython/rev/f86678551af2
changeset:   96514:f86678551af2
branch:      3.5
parent:      96512:99e6b7084c1a
user:        Benjamin Peterson <benjamin at python.org>
date:        Thu Jun 04 14:34:20 2015 -0500
summary:
  fix refleak when keys() fails

files:
  Objects/odictobject.c |  8 ++++++--
  1 files changed, 6 insertions(+), 2 deletions(-)


diff --git a/Objects/odictobject.c b/Objects/odictobject.c
--- a/Objects/odictobject.c
+++ b/Objects/odictobject.c
@@ -2427,12 +2427,16 @@
         else if (PyObject_HasAttrString(other, "keys")) {  /* never fails */
             PyObject *keys, *iterator, *key;
             keys = PyObject_CallMethod(other, "keys", NULL);
-            if (keys == NULL)
+            if (keys == NULL) {
+                Py_DECREF(other);
                 return NULL;
+            }
             iterator = PyObject_GetIter(keys);
             Py_DECREF(keys);
-            if (iterator == NULL)
+            if (iterator == NULL) {
+                Py_DECREF(other);
                 return NULL;
+            }
             while (res == 0 && (key = PyIter_Next(iterator))) {
                 PyObject *value = PyObject_GetItem(other, key);
                 if (value != NULL) {

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list