From b1efa53662385ba64289d9fe6fb8ca5b431c4119 Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Mon, 4 Mar 2013 09:47:50 -0500 Subject: [PATCH] fix possible setdefault refleak (closes #17328) --- Misc/NEWS | 2 ++ Objects/dictobject.c | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Misc/NEWS b/Misc/NEWS index 0b1da99048d..958cc1a7d45 100644 --- 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. diff --git a/Objects/dictobject.c b/Objects/dictobject.c index f4ad3dccd48..8c09e46f9bc 100644 --- a/Objects/dictobject.c +++ b/Objects/dictobject.c @@ -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;