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

Skip to content

bpo-9263: Fix _PyObject_Dump() for freed object #10661

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 22, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
bpo-9263: Fix _PyObject_Dump() for freed object
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.
  • Loading branch information
vstinner committed Nov 22, 2018
commit d5961d9e877726050978a3ff06d0bb65d0ef3945
5 changes: 5 additions & 0 deletions Objects/object.c
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,10 @@ _Py_BreakPoint(void)
int
_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));
/* ignore op->ob_ref: the value can have be modified
by Py_INCREF() and Py_DECREF(). */
Expand All @@ -448,6 +452,7 @@ _PyObject_Dump(PyObject* op)
/* It seems like the object memory has been freed:
don't access it to prevent a segmentation fault. */
fprintf(stderr, "<freed object>\n");
return;
}

PyGILState_STATE gil;
Expand Down
0