From 2ad80f53c1a9abf1d3d869a5e7902f30086f0df1 Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Thu, 4 Jun 2015 14:34:20 -0500 Subject: [PATCH] fix refleak when keys() fails --- Objects/odictobject.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Objects/odictobject.c b/Objects/odictobject.c index 313b21ae2d5..13ffdf15360 100644 --- a/Objects/odictobject.c +++ b/Objects/odictobject.c @@ -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) {