diff options
author | Victor Stinner <vstinner@redhat.com> | 2018-11-22 16:32:57 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-11-22 16:32:57 +0100 |
commit | 2cf5d32fd9e61488e8b0be55a2e92a752ba8b06b (patch) | |
tree | 78802c10dc7d34e08de079d89a2b5f42464f1f9b /Objects/object.c | |
parent | 9a0d7a7648547ffb77144bf2480155f6d7940dea (diff) | |
download | cpython-git-2cf5d32fd9e61488e8b0be55a2e92a752ba8b06b.tar.gz |
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.
Diffstat (limited to 'Objects/object.c')
-rw-r--r-- | Objects/object.c | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/Objects/object.c b/Objects/object.c index 9d2614bb6d..c2d78aa47e 100644 --- a/Objects/object.c +++ b/Objects/object.c @@ -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(). */ @@ -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; |