Date: Sun, 21 Sep 2008 17:17:27 +0300 From: Giorgos Keramidas <keramida@ceid.upatras.gr> To: trashy_bumper@yahoo.com Cc: freebsd-questions@freebsd.org Subject: Re: Segmentation fault when free Message-ID: <87vdwppoqw.fsf@kobe.laptop> In-Reply-To: <266527.92897.qm@web110502.mail.gq1.yahoo.com> (Nash Nipples's message of "Sun, 21 Sep 2008 05:57:06 -0700 (PDT)") References: <266527.92897.qm@web110502.mail.gq1.yahoo.com>
next in thread | previous in thread | raw e-mail | index | archive | help
On Sun, 21 Sep 2008 05:57:06 -0700 (PDT), Nash Nipples <trashy_bumper@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.
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?87vdwppoqw.fsf>
