Unverified Kaydet (Commit) 2cf5d32f authored tarafından Victor Stinner's avatar Victor Stinner Kaydeden (comit) GitHub

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.
üst 9a0d7a76
...@@ -423,6 +423,10 @@ _Py_BreakPoint(void) ...@@ -423,6 +423,10 @@ _Py_BreakPoint(void)
int int
_PyObject_IsFreed(PyObject *op) _PyObject_IsFreed(PyObject *op)
{ {
uintptr_t ptr = (uintptr_t)op;
if (_PyMem_IsFreed(&ptr, sizeof(ptr))) {
return 1;
}
int freed = _PyMem_IsFreed(&op->ob_type, sizeof(op->ob_type)); int freed = _PyMem_IsFreed(&op->ob_type, sizeof(op->ob_type));
/* ignore op->ob_ref: the value can have be modified /* ignore op->ob_ref: the value can have be modified
by Py_INCREF() and Py_DECREF(). */ by Py_INCREF() and Py_DECREF(). */
...@@ -448,6 +452,7 @@ _PyObject_Dump(PyObject* op) ...@@ -448,6 +452,7 @@ _PyObject_Dump(PyObject* op)
/* It seems like the object memory has been freed: /* It seems like the object memory has been freed:
don't access it to prevent a segmentation fault. */ don't access it to prevent a segmentation fault. */
fprintf(stderr, "<freed object>\n"); fprintf(stderr, "<freed object>\n");
return;
} }
PyGILState_STATE gil; PyGILState_STATE gil;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment