Re: writing to freed memory--issues



"bill pursell" <bill.pursell@xxxxxxxxx> writes:

I was playing around with a toy program, which led to some confusion.
I had expected that doing the following would lead to an immediate
segfault:
free(a);
*a=0;
However, it did not. Further investigation showed that I could free a

Don't bother. Accessing freed memory causes undefined behavior. It
might work (as in load instructions completing normally), or it might
segfault, or it might turn you into a toad. Exactly what happens
depends on your operating system and malloc() implementation, among
many other factors.

The only thing you need to know is that accessing freed memory is
*never* a valid thing to do.

--
Måns Rullgård
mru@xxxxxxxxxxxxx
.