]> granicus.if.org Git - python/commitdiff
bpo-38070: visit_decref() calls _PyObject_IsFreed() (GH-15782)
authorVictor Stinner <vstinner@redhat.com>
Mon, 9 Sep 2019 15:44:59 +0000 (17:44 +0200)
committerGitHub <noreply@github.com>
Mon, 9 Sep 2019 15:44:59 +0000 (17:44 +0200)
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.

Modules/gcmodule.c

index 134f6d168c9616a86d9f4e6d1e26a00a5a42fac9..f6e841d52ff90a39d94f62cd81cd83ad79997a18 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