Segmentation fault when free

RW fbsd06 at
Mon Sep 22 01:43:03 UTC 2008

On Sun, 21 Sep 2008 05:57:06 -0700 (PDT)
Nash Nipples <trashy_bumper at> wrote:

> 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.

The idea that malloc() allocates memory is really a C language
abstraction. What it actually does is allocate a region in the
process's virtual address space. The mapping of physical memory to
virtual address space is handled at a lower-level and doesn't rely on
malloc() or free().

> in other words segmentation fault when free() is not a scary thing
> here. it is a matter of style and the way to find own errors. or
> maybe reading warnings if you compile with the flags -ansi -pedantic 

I'm not sure what you are saying here, but the handling of dynamic
memory in C is something that needs to be well thought-out in
advance. Bugs is this area can be very difficult and time-consuming
to track-down. 

> oh and by the way:
> >     char *
> >     function(void)
> >     {
> >         char buffer[100];
> > 
> >         return buffer;
> >     }
> that is an easier approach because you get warned on passing an
> address to a local variable

This was an example of how to generate a failure, it's not an approach.

More information about the freebsd-questions mailing list