diff options
author | Inada Naoki <songofacandy@gmail.com> | 2022-03-03 05:30:58 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-03 05:30:58 (GMT) |
commit | 3241cba4ec55ef0b9e73bf7a5a77ef29ae4b8756 (patch) | |
tree | 89195e2339dbf8e270643928133bafc9e3479903 /Objects/dictobject.c | |
parent | 59e1ce95f1e6ea8a556212b8b10cbc122f1a1711 (diff) | |
download | cpython-3241cba4ec55ef0b9e73bf7a5a77ef29ae4b8756.zip cpython-3241cba4ec55ef0b9e73bf7a5a77ef29ae4b8756.tar.gz cpython-3241cba4ec55ef0b9e73bf7a5a77ef29ae4b8756.tar.bz2 |
dict: Fix refleak (GH-31650)
Diffstat (limited to 'Objects/dictobject.c')
-rw-r--r-- | Objects/dictobject.c | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/Objects/dictobject.c b/Objects/dictobject.c index abe455e..d8bf164 100644 --- a/Objects/dictobject.c +++ b/Objects/dictobject.c @@ -1523,12 +1523,16 @@ dictresize(PyDictObject *mp, uint8_t log2_newsize, int unicode) // We can not use free_keys_object here because key's reference // are moved already. - if (oldkeys != Py_EMPTY_KEYS) { - assert(oldkeys->dk_kind != DICT_KEYS_SPLIT); - assert(oldkeys->dk_refcnt == 1); #ifdef Py_REF_DEBUG - _Py_RefTotal--; + _Py_RefTotal--; #endif + if (oldkeys == Py_EMPTY_KEYS) { + oldkeys->dk_refcnt--; + assert(oldkeys->dk_refcnt > 0); + } + else { + assert(oldkeys->dk_kind != DICT_KEYS_SPLIT); + assert(oldkeys->dk_refcnt == 1); #if PyDict_MAXFREELIST > 0 struct _Py_dict_state *state = get_dict_state(); #ifdef Py_DEBUG |