Skip to content

Commit 3241cba

Browse files
authored
dict: Fix refleak (GH-31650)
1 parent 59e1ce9 commit 3241cba

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

Objects/dictobject.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1523,12 +1523,16 @@ dictresize(PyDictObject *mp, uint8_t log2_newsize, int unicode)
15231523

15241524
// We can not use free_keys_object here because key's reference
15251525
// are moved already.
1526-
if (oldkeys != Py_EMPTY_KEYS) {
1527-
assert(oldkeys->dk_kind != DICT_KEYS_SPLIT);
1528-
assert(oldkeys->dk_refcnt == 1);
15291526
#ifdef Py_REF_DEBUG
1530-
_Py_RefTotal--;
1527+
_Py_RefTotal--;
15311528
#endif
1529+
if (oldkeys == Py_EMPTY_KEYS) {
1530+
oldkeys->dk_refcnt--;
1531+
assert(oldkeys->dk_refcnt > 0);
1532+
}
1533+
else {
1534+
assert(oldkeys->dk_kind != DICT_KEYS_SPLIT);
1535+
assert(oldkeys->dk_refcnt == 1);
15321536
#if PyDict_MAXFREELIST > 0
15331537
struct _Py_dict_state *state = get_dict_state();
15341538
#ifdef Py_DEBUG

0 commit comments

Comments
 (0)