Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 20 Sep 2008 02:06:02 -0700 (PDT)
From:      Unga <unga888@yahoo.com>
To:        Giorgos Keramidas <keramida@ceid.upatras.gr>
Cc:        freebsd-questions@freebsd.org
Subject:   Re: Segmentation fault when free
Message-ID:  <958402.1645.qm@web57004.mail.re3.yahoo.com>
In-Reply-To: <87bpyj9qi9.fsf@kobe.laptop>

next in thread | previous in thread | raw e-mail | index | archive | help



--- On Sat, 9/20/08, Giorgos Keramidas <keramida@ceid.upatras.gr> wrote:

> > 1. This clearly shows my program is trying to free a
> memory that has
> > not been allocated. How it could have happened?
> 
> Aha.  This looks remarkably like an address in the runtime
> stack.  It
> usually happens when you have a function that returns the
> address of a
> 'local' variable, instead of a newly allocated heap
> area, i.e.:
> 
>     char *
>     function(void)
>     {
>         char buffer[100];
> 
>         return buf;
>     }
> 

This problem happens very early stage of my program. Its the very first free() develops a problem. 

I checked again, up to the this problematic free(), functions return newly allocated strings properly:

char *f( )
{
 char *newstr = NULL;
:
 newstr = (char *) malloc(p - sp + 1);
 if (newstr == NULL)
    return NULL;
 :
 return newstr;
}

Can a yet not executed wrong free() elsewhere cause a problem of this nature?

Best regards
Unga


      



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?958402.1645.qm>