From 01a5920c3d1d8ab7e2fa1bca281a94f2162f2e98 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Mon, 9 Sep 2019 17:44:59 +0200 Subject: [PATCH] bpo-38070: visit_decref() calls _PyObject_IsFreed() (GH-15782) 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 --- Modules/gcmodule.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Modules/gcmodule.c b/Modules/gcmodule.c index 2741edc0a0211c..b2ee56623cd484 100644 --- a/Modules/gcmodule.c +++ b/Modules/gcmodule.c @@ -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