effect of free()

John Stanley john at ontek.UUCP
Sat Sep 9 09:07:10 AEST 1989


In article <248 at seti.inria.fr>, jourdan at seti.inria.fr (jourdan martin joseph) writes:
> The morale of the whole story is: DO NOT DO ANYTHING WITH A FREED
> POINTER.  To make things safer, each time I free a pointer variable,
> the next statement is to copy some valid pointer value (usually NULL)
> into it.  Of course, that does not solve the aliasing problem which
> was the basis of the whole discussion, but that alleviates many
> problems.

What I usually do is to NULL out the entire structure (or whatever) that is
being pointed at before freeing it.  This does not prevent an aliased access,
but it does increase the probability of it being noticed as soon as possible.

	 JAS



More information about the Comp.lang.c mailing list