Re: Segmentation fault when free

2008-09-21 Thread Giorgos Keramidas
On Mon, 22 Sep 2008 02:31:57 +0100, RW <[EMAIL PROTECTED]> wrote: >Nash Nipples <[EMAIL PROTECTED]> wrote: >>Giorgos Keramidas wrote: >>> char * >>> function(void) >>> { >>> char buffer[100]; >>> >>> return buffer; >>> } >> >> that is an easier approach because you g

Re: Segmentation fault when free

2008-09-21 Thread RW
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

Re: Segmentation fault when free

2008-09-21 Thread Mel
On Sunday 21 September 2008 14:57:06 Nash Nipples wrote: > > > can someone please explain to me what happens to the > > > > allocated memory > > > > > called within a function assigned to its local pointer > > > > after this function > > > > > ends > > > > Ok - let's see if I get this right: > > -

Re: Segmentation fault when free

2008-09-21 Thread Giorgos Keramidas
On Sun, 21 Sep 2008 05:57:06 -0700 (PDT), Nash Nipples <[EMAIL PROTECTED]> 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 t

Re: Segmentation fault when free

2008-09-21 Thread Nash Nipples
culous size */ } } 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. in other words segmentation fault when free() is not a scary thing here.

Re: Segmentation fault when free

2008-09-20 Thread Mel
On Saturday 20 September 2008 13:46:23 Nash Nipples wrote: > can someone please explain to me what happens to the allocated memory > called within a function assigned to its local pointer after this function > ends Ok - let's see if I get this right: - the allocated memory - called within a func

Re: Segmentation fault when free [SOLVED]

2008-09-20 Thread Giorgos Keramidas
On Sat, 20 Sep 2008 07:04:03 -0700 (PDT), Unga <[EMAIL PROTECTED]> wrote: >On Sat, 9/20/08, Giorgos Keramidas <[EMAIL PROTECTED]> wrote: >>> : free(0xbfbfc9c9) >>> >>> 1. This clearly shows my program is trying to free a memory that >>> has not been allocated. How it could have happened? >> >> Aha.

Re: Segmentation fault when free [SOLVED]

2008-09-20 Thread Unga
--- On Sat, 9/20/08, Giorgos Keramidas <[EMAIL PROTECTED]> wrote: > > ktrace.out shows: > > malloc_init() > > 0x8103400 = malloc(1024) > > malloc_init() > > malloc_init() > > 0x810b0b0 = malloc(400) > > : > > so many malloc > > : > > so many free > > : > > malloc/free combinations > > : > > free(0

Re: Segmentation fault when free

2008-09-20 Thread Nash Nipples
actually what i think someone should really tell you is that maybe you should take a look at the free() manual which is available here http://www.freebsd.org/cgi/man.cgi?query=free&apropos=0&sektion=0&manpath=FreeBSD+7.0-RELEASE&format=html or you can try to run `man free` in the console. there i

Re: Segmentation fault when free

2008-09-20 Thread Nash Nipples
> 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

Re: Segmentation fault when free

2008-09-20 Thread Unga
--- On Sat, 9/20/08, Giorgos Keramidas <[EMAIL PROTECTED]> 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 yo

Re: Segmentation fault when free

2008-09-20 Thread Giorgos Keramidas
On Sat, 20 Sep 2008 00:31:41 -0700 (PDT), Unga <[EMAIL PROTECTED]> wrote: > --- On Sat, 9/20/08, Giorgos Keramidas <[EMAIL PROTECTED]> wrote: >> You are probably calling free() multiple times for the same buffer. >> >> Try tracing the malloc and free calls, using the information from >> this messag

Re: Segmentation fault when free

2008-09-20 Thread Unga
--- On Sat, 9/20/08, Giorgos Keramidas <[EMAIL PROTECTED]> wrote: > From: Giorgos Keramidas <[EMAIL PROTECTED]> > Subject: Re: Segmentation fault when free > To: [EMAIL PROTECTED] > Cc: [EMAIL PROTECTED], freebsd-questions@freebsd.org > Date: Saturday, September 20,

Re: Segmentation fault when free

2008-09-19 Thread Giorgos Keramidas
On Fri, 19 Sep 2008 20:03:03 -0700 (PDT), Unga <[EMAIL PROTECTED]> wrote: > Hi thank you very much for your reply and the test case. > > That is, in a trivial case like this, free() works well. Hopefully > free() works well in all cases too. > > But my main program is 1900 lines, f1() and f2() are

Re: Segmentation fault when free

2008-09-19 Thread Unga
--- On Sat, 9/20/08, Nash Nipples <[EMAIL PROTECTED]> wrote: > From: Nash Nipples <[EMAIL PROTECTED]> > Subject: Re: Segmentation fault when free > To: freebsd-questions@freebsd.org > Date: Saturday, September 20, 2008, 4:14 AM > --- On Fri, 9/19/08, Unga <[EMAIL

Re: Segmentation fault when free

2008-09-19 Thread Nash Nipples
--- On Fri, 9/19/08, Unga <[EMAIL PROTECTED]> wrote: > From: Unga <[EMAIL PROTECTED]> > Subject: Segmentation fault when free > To: freebsd-questions@freebsd.org > Date: Friday, September 19, 2008, 9:17 AM > Hi all > > I'm running FreeBSD 7 on i386.

Segmentation fault when free

2008-09-19 Thread Unga
Hi all I'm running FreeBSD 7 on i386. I have a C program compiled with gcc 4.2.1 20070719. Logically my program is: char *a; char *b; char *c; while (cond) { a = f1(); /* malloc() and send a string */ b = f2(); /* malloc() and send a string */ c = (char *) malloc(strlen(a) + strlen(b) + 1)