This is an old copy of the Python FAQ. The information here may be outdated.

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} and PyMem_{Free, FREE} no longer map to PyObject_{Free, FREE}. They map to the system free() now. If memory is obtained via the PyObject_ family, it must be released via the PyObject_ family, and likewise for the PyMem_ 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 via PyObject_New but released it via PyMem_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


A Django site. rendered by a django application. hosted by webfaction.