]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
dict: Fix refleak (GH-31650)
authorInada Naoki <songofacandy@gmail.com>
Thu, 3 Mar 2022 05:30:58 +0000 (14:30 +0900)
committerGitHub <noreply@github.com>
Thu, 3 Mar 2022 05:30:58 +0000 (14:30 +0900)
Objects/dictobject.c

index abe455e4ae0346999e4dd387d7d1b3e05eb1f549..d8bf164f98ee6b60a5b3dea7556be73457ca34d3 100644 (file)
@@ -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