]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-38070: visit_decref() calls _PyObject_IsFreed() (GH-15782)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Mon, 9 Sep 2019 17:18:09 +0000 (10:18 -0700)
committerGitHub <noreply@github.com>
Mon, 9 Sep 2019 17:18:09 +0000 (10:18 -0700)
In debug mode, visit_decref() now calls _PyObject_IsFreed() to ensure
that the object is not freed. If it's freed, the program fails with
an assertion error and Python dumps informations about the freed
object.
(cherry picked from commit d91d4de31745fc1ed4c7e6c208917827c9c472b6)

Co-authored-by: Victor Stinner <vstinner@redhat.com>
Modules/gcmodule.c

index 2741edc0a0211c9172f15af404ee46d30701b63f..b2ee56623cd4844b2349658f557d1a36421e9b88 100644 (file)
@@ -376,6 +376,8 @@ static int
 visit_decref(PyObject *op, void *data)
 {
     assert(op != NULL);
+    _PyObject_ASSERT(op, !_PyObject_IsFreed(op));
+
     if (PyObject_IS_GC(op)) {
         PyGC_Head *gc = AS_GC(op);
         /* We're only interested in gc_refs for objects in the