Skip to content

Commit 5731172

Browse files
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 d91d4de) Co-authored-by: Victor Stinner <[email protected]>
1 parent 2d5594f commit 5731172

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

Modules/gcmodule.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,8 @@ static int
376376
visit_decref(PyObject *op, void *data)
377377
{
378378
assert(op != NULL);
379+
_PyObject_ASSERT(op, !_PyObject_IsFreed(op));
380+
379381
if (PyObject_IS_GC(op)) {
380382
PyGC_Head *gc = AS_GC(op);
381383
/* We're only interested in gc_refs for objects in the

0 commit comments

Comments
 (0)