This program makes Python segfault - no other does

Christophe Cavalaria chris.cavalaria at free.fr
Tue May 18 15:14:20 EDT 2004


Juho Saarikko wrote:

> The function unQuoteBytea allocates memory with PyMem_Malloc, and frees it
> with PyMem_Free. The segfault happens at freeing the memory (as the
> backtrace shows). It seems to me that if Python's memory management
> routines fail to free an object they've allocated, it must be a bug in
> Python. That or some other bug corrupts memory structures, in which case
> it's almost impossible to track down.

As a rule of thumb, you should assume that malloc and fre aren't bugged at
all. It is far easier to crash a free call than to find a bug *in* free.

Example code that will likely segfault in free or at the program exit/next
malloc :

free((void*)1);


void * a = malloc(2);
free(a);
free(a);


char * a = malloc(2);
free(a+1);


etc...




More information about the Python-list mailing list