]> granicus.if.org Git - python/commitdiff
fix possible setdefault refleak (closes #17328)
authorBenjamin Peterson <benjamin@python.org>
Mon, 4 Mar 2013 14:47:50 +0000 (09:47 -0500)
committerBenjamin Peterson <benjamin@python.org>
Mon, 4 Mar 2013 14:47:50 +0000 (09:47 -0500)
Misc/NEWS
Objects/dictobject.c

index 0b1da99048d6cefea48de423e260e51de04435f6..958cc1a7d45ea65366917ca8b7a1f09258e5057b 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -12,6 +12,8 @@ What's New in Python 3.3.1?
 Core and Builtins
 -----------------
 
+- Issue #17328: Fix possible refleak in dict.setdefault.
+
 - Issue #17223: array module: Fix a crasher when converting an array containing
   invalid characters (outside range [U+0000; U+10ffff]) to Unicode:
   repr(array), str(array) and array.tounicode(). Patch written by Manuel Jacob.
index f4ad3dccd48eabc279923ae1b63b4c1dbaa51cf4..8c09e46f9bc5600ab1b01df1c2f70158138d0e52 100644 (file)
@@ -2230,14 +2230,14 @@ dict_setdefault(register PyDictObject *mp, PyObject *args)
         return NULL;
     val = *value_addr;
     if (val == NULL) {
-        Py_INCREF(failobj);
-        Py_INCREF(key);
         if (mp->ma_keys->dk_usable <= 0) {
             /* Need to resize. */
             if (insertion_resize(mp) < 0)
                 return NULL;
             ep = find_empty_slot(mp, key, hash, &value_addr);
         }
+        Py_INCREF(failobj);
+        Py_INCREF(key);
         MAINTAIN_TRACKING(mp, key, failobj);
         ep->me_key = key;
         ep->me_hash = hash;