effect of free()

Doug Gwyn gwyn at smoke.BRL.MIL
Sat Sep 9 19:07:00 AEST 1989


In article <549 at ontek.UUCP> john at ontek.UUCP (John Stanley) writes:
>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.

We also did this in our humongous project, in debugging mode
(which also turns on very extensive validity checks throughout
the code).  It turned out that changing the "zap" to fill the
blocks with all ON bits caught several bugs that zapping the
blocks to all OFF bits (i.e. 0) didn't.  I'm sure the reverse
would have been true too if we'd done it in the opposite order.

It may be worth mentioning that the sensible way to do this
stuff is in a package of library routines that all your projects
use.  That way it happens globally and doesn't require a lot of
extra typing on the coder's part.



More information about the Comp.lang.c mailing list