]> granicus.if.org Git - python/commitdiff
Issue #13018: Fix reference leaks in error paths in dictobject.c.
authorPetri Lehtinen <petri@digip.org>
Mon, 24 Oct 2011 17:59:29 +0000 (20:59 +0300)
committerPetri Lehtinen <petri@digip.org>
Mon, 24 Oct 2011 17:59:29 +0000 (20:59 +0300)
Patch by Suman Saha.

Misc/NEWS
Objects/dictobject.c

index 7b793b26908bbb1272200bfab1b25d4e694c6586..7741e2cb8aafb705d67fdfb799fc02f272eb4c0d 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -9,6 +9,9 @@ What's New in Python 2.7.3?
 Core and Builtins
 -----------------
 
+- Issue #13018: Fix reference leaks in error paths in dictobject.c.
+  Patch by Suman Saha.
+
 - Issue #12604: VTRACE macro expanded to no-op in _sre.c to avoid compiler
   warnings. Patch by Josh Triplett and Petri Lehtinen.
 
index e8f8b4a8463f085a980c93eb44288c92538d58a9..f2ebf456b469fdcd3474d7db28e87a237a99c227 100644 (file)
@@ -1335,14 +1335,18 @@ dict_fromkeys(PyObject *cls, PyObject *args)
         PyObject *key;
         long hash;
 
-        if (dictresize(mp, Py_SIZE(seq)))
+        if (dictresize(mp, Py_SIZE(seq))) {
+            Py_DECREF(d);
             return NULL;
+        }
 
         while (_PyDict_Next(seq, &pos, &key, &oldvalue, &hash)) {
             Py_INCREF(key);
             Py_INCREF(value);
-            if (insertdict(mp, key, hash, value))
+            if (insertdict(mp, key, hash, value)) {
+                Py_DECREF(d);
                 return NULL;
+            }
         }
         return d;
     }
@@ -1353,14 +1357,18 @@ dict_fromkeys(PyObject *cls, PyObject *args)
         PyObject *key;
         long hash;
 
-        if (dictresize(mp, PySet_GET_SIZE(seq)))
+        if (dictresize(mp, PySet_GET_SIZE(seq))) {
+            Py_DECREF(d);
             return NULL;
+        }
 
         while (_PySet_NextEntry(seq, &pos, &key, &hash)) {
             Py_INCREF(key);
             Py_INCREF(value);
-            if (insertdict(mp, key, hash, value))
+            if (insertdict(mp, key, hash, value)) {
+                Py_DECREF(d);
                 return NULL;
+            }
         }
         return d;
     }