8000 bpo-9263: Fix _PyObject_Dump() for freed object (#10661) · python/cpython@2cf5d32 · GitHub
[go: up one dir, main page]

Skip to content
8000

Commit 2cf5d32

Browse files
authored
bpo-9263: Fix _PyObject_Dump() for freed object (#10661)
If _PyObject_Dump() detects that the object is freed, don't try to dump it (exit immediately). Enhance also _PyObject_IsFreed(): it now detects if the pointer itself looks like freed memory.
1 parent 9a0d7a7 commit 2cf5d32

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

Objects/object.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,10 @@ _Py_BreakPoint(void)
423423
int
424424
_PyObject_IsFreed(PyObject *op)
425425
{
426+
uintptr_t ptr = (uintptr_t)op;
427+
if (_PyMem_IsFreed(&ptr, sizeof(ptr))) {
428+
return 1;
429+
}
426430
int freed = _PyMem_IsFreed(&op->ob_type, sizeof(op->ob_type));
427431
/* ignore op->ob_ref: the value can have be modified
428432
by Py_INCREF() and Py_DECREF(). */
@@ -448,6 +452,7 @@ _PyObject_Dump(PyObject* op)
448452
/* It seems like the object memory has been freed:
449453
don't access it to prevent a segmentation fault. */
450454
fprintf(stderr, "<freed object>\n");
455+
return;
451456
}
452457

453458
PyGILState_STATE gil;

0 commit comments

Comments
 (0)
0