Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!csd4.csd.uwm.edu!uakari.primate.wisc.edu!aplcen!haven!adm!smoke!gwyn From: gwyn@smoke.BRL.MIL (Doug Gwyn) Newsgroups: comp.lang.c Subject: Re: effect of free() Message-ID: <11010@smoke.BRL.MIL> Date: 9 Sep 89 09:07:00 GMT References: <319@cubmol.BIO.COLUMBIA.EDU> <3756@buengc.BU.EDU> <248@seti.inria.fr> <549@ontek.UUCP> Reply-To: gwyn@brl.arpa (Doug Gwyn) Organization: Ballistic Research Lab (BRL), APG, MD. Lines: 16 In article <549@ontek.UUCP> john@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.