Why does my C extension suddenly crash under 2.5?
If you have a well-tested C extension that suddenly starts misbehaving under Python 2.5, a possible reason can be that your code uses PyObject_New to allocate object memory, but PyMem_Free to release it. This used to work, but no longer works under Python 2.5’s modified memory allocator.
Quoting from Misc/NEWS:
PyMem_{Del, DEL}andPyMem_{Free, FREE}no longer map toPyObject_{Free, FREE}. They map to the systemfree()now. If memory is obtained via thePyObject_family, it must be released via thePyObject_family, and likewise for thePyMem_family. This has always been officially true, but when Python’s small-object allocator was introduced, an attempt was made to cater to a few extension modules discovered at the time that obtained memory viaPyObject_Newbut released it viaPyMem_DEL. It’s years later, and if such code still exists it will fail now (probably with segfaults, but calling wrong low-level memory management functions can yield many symptoms).
If running under the Visual C debugger, this typically results in the following message:
HEAP[python.exe]: Invalid Address specified to RtlFreeHeap( 009B0000, 00BE5660 )
Unhandled exception at 0x7c901230 in python.exe: User breakpoint.
CATEGORY: extending