david wrote:
> I don't know why free causes some segfault when called several times
> on the same pointer. ( I don't even know how malloc works.).
malloc() normally allocates an oversized block, stores some
information (e.g. the size of the block) at the start of the block,
and returns a pointer to the space following the `header'.
free() expects this header to exist. It typically modifies the header
(e.g. storing a pointer to the next block on a list of free blocks, or
similar).
IOW, malloc()d blocks start with an `allocated block' header; free()d
blocks start with a `free block' header. free() assumes that the data
preceding the address is an `allocated block' header, and will behave
unpredictably if it isn't.
--
Glynn Clements <[EMAIL PROTECTED]>