Segmentation fault when free
Giorgos Keramidas
keramida at ceid.upatras.gr
Sun Sep 21 14:17:47 UTC 2008
On Sun, 21 Sep 2008 05:57:06 -0700 (PDT), Nash Nipples <trashy_bumper at yahoo.com> wrote:
> thanks for making it even more clear to me.
> actually what i meant was this:
>
> void function(void){
> char *p;
> p = malloc(1);
> }
> int main(void){
> while (1){
> function();
> /* in the end of this function function()
> * the memory is still allocated
> * even when the only pointer who knows its address
> * does not longer exist
> * which is why we have to free() the memory
> * during the application runtime
> * to avoid it from growing to ridiculous size
> */
> }
> }
This won't throw SEGV in free() because, well, it never calls free(),
but it leaks memory like mad :)
> but even if you kill -SEGV `pgrep this` (Segmentation fault (core
> dumped) the memory is getting freed anyway (presumably by the glorious
> kernel). which you can see dynamicly by typing top in the console.
Yes. When a process terminates, the kernel dismantles and releases all
its 'mapped memory areas', including the heap where malloc()'ed memory
comes from.
More information about the freebsd-questions
mailing list