You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
gh-118909: Fix crash freeing tp_doc allocated with PyObject_Malloc()
type_dealloc() always freed a heap type's tp_doc with PyMem_Free(),
but some C extensions (e.g. older pybind11 and nanobind versions)
allocate it directly with PyObject_Malloc() instead, relying on
CPython to free it. The two allocator domains share the same
underlying allocator in a release build, so this went unnoticed, but
a build with debug allocator hooks enabled (Py_DEBUG, or
PYTHONMALLOC=debug) tags each domain's blocks and aborts when a block
is freed with the mismatched domain.
Detect which allocator was actually used, from the tag debug builds
write before the returned pointer, and free with the matching
function as a backwards-compatibility fallback.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
0 commit comments