Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b1efa53

Browse files
committed
fix possible setdefault refleak (closes #17328)
1 parent 2960693 commit b1efa53

2 files changed

Lines changed: 4 additions & 2 deletions

File tree

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ What's New in Python 3.3.1?
1212
Core and Builtins
1313
-----------------
1414

15+
- Issue #17328: Fix possible refleak in dict.setdefault.
16+
1517
- Issue #17223: array module: Fix a crasher when converting an array containing
1618
invalid characters (outside range [U+0000; U+10ffff]) to Unicode:
1719
repr(array), str(array) and array.tounicode(). Patch written by Manuel Jacob.

Objects/dictobject.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2230,14 +2230,14 @@ dict_setdefault(register PyDictObject *mp, PyObject *args)
22302230
return NULL;
22312231
val = *value_addr;
22322232
if (val == NULL) {
2233-
Py_INCREF(failobj);
2234-
Py_INCREF(key);
22352233
if (mp->ma_keys->dk_usable <= 0) {
22362234
/* Need to resize. */
22372235
if (insertion_resize(mp) < 0)
22382236
return NULL;
22392237
ep = find_empty_slot(mp, key, hash, &value_addr);
22402238
}
2239+
Py_INCREF(failobj);
2240+
Py_INCREF(key);
22412241
MAINTAIN_TRACKING(mp, key, failobj);
22422242
ep->me_key = key;
22432243
ep->me_hash = hash;

0 commit comments

Comments
 (0)