]> granicus.if.org Git - python/commitdiff
fix refleak when keys() fails
authorBenjamin Peterson <benjamin@python.org>
Thu, 4 Jun 2015 19:34:20 +0000 (14:34 -0500)
committerBenjamin Peterson <benjamin@python.org>
Thu, 4 Jun 2015 19:34:20 +0000 (14:34 -0500)
Objects/odictobject.c

index 313b21ae2d546b4a941c4a61d695adfdb2a25025..13ffdf15360396896dbc7bcb69cbf74a656b3484 100644 (file)
@@ -2427,12 +2427,16 @@ mutablemapping_update(PyObject *self, PyObject *args, PyObject *kwargs)
         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) {