summaryrefslogtreecommitdiffstats
path: root/Objects/dictobject.c
diff options
context:
space:
mode:
authorYury Selivanov <yury@magic.io>2018-07-06 16:20:07 (GMT)
committerGitHub <noreply@github.com>2018-07-06 16:20:07 (GMT)
commit0b75228700e0077d8bf2636e74733389514b4b2f (patch)
tree71286b01828ff373515ab058c9d7640b9e19eb5e /Objects/dictobject.c
parentdc9bc548994066897ca4edfdbf36ea9272bfdee9 (diff)
downloadcpython-0b75228700e0077d8bf2636e74733389514b4b2f.zip
cpython-0b75228700e0077d8bf2636e74733389514b4b2f.tar.gz
cpython-0b75228700e0077d8bf2636e74733389514b4b2f.tar.bz2
bpo-34042: Fix dict.copy() to maintain correct total refcount (GH-8119)
Diffstat (limited to 'Objects/dictobject.c')
-rw-r--r--Objects/dictobject.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/Objects/dictobject.c b/Objects/dictobject.c
index 40d7d8a..413557d 100644
--- a/Objects/dictobject.c
+++ b/Objects/dictobject.c
@@ -656,6 +656,13 @@ clone_combined_dict(PyDictObject *orig)
/* Maintain tracking. */
_PyObject_GC_TRACK(new);
}
+
+ /* Since we copied the keys table we now have an extra reference
+ in the system. Manually call _Py_INC_REFTOTAL to signal that
+ we have it now; calling DK_INCREF would be an error as
+ keys->dk_refcnt is already set to 1 (after memcpy). */
+ _Py_INC_REFTOTAL;
+
return (PyObject *)new;
}