This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] C undefined behavior fix
Paul Mackerras <paulus@samba.org> writes:
> I looked at this, and it starts out with an example that includes a
> statement free(p); (where p was assigned a value returned from malloc)
> and then states that "After the call to free the value of p is
> indeterminate."!
>
> This seems absolutely and completely bogus to me. Certainly, after
> the free, the value of *p is indeterminate, but the value of p itself
> *is* determinate; its value after the free is identical to its value
> before the free. Why do they say that the value of p itself is
> indeterminate after the free?
One reason is that on some segmented machines, just loading the value
of 'p' into a segment register may cause an exception once its segment
has gone away.
Another reason is to support garbage collection; you might want
'free(p)' to explicitly clear p and any other references to it that
can be found in the hope that will let the space be collected.
--
- Geoffrey Keating <geoffk@geoffk.org> <geoffk@redhat.com>