[Python-checkins] dict: Fix refleak (GH-31650)

methane webhook-mailer at python.org
Thu Mar 3 00:31:13 EST 2022


https://github.com/python/cpython/commit/3241cba4ec55ef0b9e73bf7a5a77ef29ae4b8756
commit: 3241cba4ec55ef0b9e73bf7a5a77ef29ae4b8756
branch: main
author: Inada Naoki <songofacandy at gmail.com>
committer: methane <songofacandy at gmail.com>
date: 2022-03-03T14:30:58+09:00
summary:

dict: Fix refleak (GH-31650)

files:
M Objects/dictobject.c

diff --git a/Objects/dictobject.c b/Objects/dictobject.c
index abe455e4ae034..d8bf164f98ee6 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



More information about the Python-checkins mailing list