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
{{ message }}
Repository navigation
Destructing _datetime in sub-interpreters in the same time may crash the process #136423
PS C:\Users\xxxxx\Source\cpython> .\python.bat .\a.py
Running Debug|x64 interpreter...
<module '_datetime' (built-in)>
<module '_datetime' (built-in)>
Debug memory block at address p=000002340D505A70: API '?
15987178197214944733 bytes originally requested
The 7 pad bytes at p-7 are not all FORBIDDENBYTE (0xfd):
at p-7: 0xdd *** OUCH
at p-6: 0xdd *** OUCH
at p-5: 0xdd *** OUCH
at p-4: 0xdd *** OUCH
at p-3: 0xdd *** OUCH
at p-2: 0xdd *** OUCH
at p-1: 0xdd *** OUCH
Because memory is corrupted at the start, the count of bytes requested
may be bogus, and checking the trailing pad bytes may segfault.
The 8 pad bytes at tail=DDDDE011EB2E384D are
I think there is a double free here.
Please note that there is a similar issue may crash the interpreter but in the initializing phase: #136421
CPython versions tested on:
CPython main branch
Operating systems tested on:
macOS, Windows
Output from running 'python -VV' on the command line:
changed the title [-]Destructing _datetime in sub-interpreters in the same time may crash the process[/-][+]Destructing `_datetime` in sub-interpreters in the same time may crash the process[/+]on Jul 8, 2025
It seems like Py_TPFLAGS_READY is cleared before managed_static_type_state_clear(), which conficts with _PyStaticType_InitForExtension() then crashes at _PyObject_ClearFreeLists().
Activity
aisk commentedon Jul 8, 2025
cc @ericsnowcurrently
[-]Destructing _datetime in sub-interpreters in the same time may crash the process[/-][+]Destructing `_datetime` in sub-interpreters in the same time may crash the process[/+]seuwebber commentedon Jul 9, 2025
I encountered the same bug while using the C Python API.
neonene commentedon Jul 12, 2025
It seems like
Py_TPFLAGS_READYis cleared beforemanaged_static_type_state_clear(), which conficts with_PyStaticType_InitForExtension()then crashes at_PyObject_ClearFreeLists().cpython/Objects/typeobject.c
Lines 6606 to 6616 in db47f4d
managed_static_type_state_clear()invokes:cpython/Objects/typeobject.c
Lines 254 to 258 in db47f4d
So, a possible workaround only for this issue would be:
int _PyStaticType_InitForExtension(PyInterpreterState *interp, PyTypeObject *self) { - return init_static_type(interp, self, 0, ((self->tp_flags & Py_TPFLAGS_READY) == 0)); + return init_static_type(interp, self, 0, self->tp_subclasses == NULL); }kumaraditya303 commentedon Jul 21, 2025
Fixed by #136583