effect of free()

Doug Gwyn gwyn at smoke.BRL.MIL
Thu Aug 24 01:51:58 AEST 1989


In article <572 at augean.OZ> idall at augean.OZ (Ian Dall) writes:
>In article <14343 at haddock.ima.isc.com> karl at haddock.ima.isc.com (Karl Heuer) writes:
>>The issue is not whether the value of ptr has changed.  Some architectures
>>distinguish between arithmetic registers and address registers, and refuse to
>>allow arbitrary garbage to be loaded into an address register.
>"free" or ANY function cannot change it's argument. "free" should not load
>anything into "the special address register" (let alone "arbitrary garbage").

No, Karl knows what he's talking about.  A formerly valid pointer value
can become invalid as a side-effect of free()'s operation.  The machine
could barf if you continue to access the now-invalid pointer value (NOT
just what it points at, but the pointer itself).  There are admittedly
not many architectures like this in common use, but if you're striving
for maximum portability you might as well be aware of the possibility.



More information about the Comp.lang.c mailing list