Segmentation fault when free
unga888 at yahoo.com
Sat Sep 20 07:31:42 UTC 2008
--- On Sat, 9/20/08, Giorgos Keramidas <keramida at ceid.upatras.gr> wrote:
> From: Giorgos Keramidas <keramida at ceid.upatras.gr>
> Subject: Re: Segmentation fault when free
> To: unga888 at yahoo.com
> Cc: trashy_bumper at yahoo.com, freebsd-questions at freebsd.org
> Date: Saturday, September 20, 2008, 2:23 PM
> On Fri, 19 Sep 2008 20:03:03 -0700 (PDT), Unga
> <unga888 at yahoo.com> wrote:
> > Hi thank you very much for your reply and the test
> > 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
> in a 2200 lines
> > second file. The f1() and f2() calls some functions
> from a 500 lines
> > third file. The main program call another function,
> f3(), from 2nd
> > file, pass pointers to two functions f4(), f5() of
> main program. The
> > while loop iterate more than one million times. Its
> quite a complex
> > situation.
> You are probably calling free() multiple times for the same
> Try tracing the malloc and free calls, using the
> information from this
> > There must be an error somewhere else. I noted free()
> causes lot of
> > troubles. It is easy to write complex programs if you
> just let to leak
> > memory. But in my case, since the program iterate
> millions of times,
> > if I let to leak, I'm sure it will run out of RAM.
> Leaking memory is *never* a good choice. Especially if you
> are writing
> library code that others are supposed to use, or code that
> is supposed
> to run millions of times.
> While it's understandable as a 'quick hack'
> when you are first writing a
> program, I've seen far too many 'quick hacks'
> that lived years and years
> after the original 'experimental' period passed.
> Hence the knee-jerk
> reaction when I see leaks being used as a
> 'temporary' solution :)
Hi Giorgos, thank you very much for your reply.
0x8103400 = malloc(1024)
0x810b0b0 = malloc(400)
so many malloc
so many free
1. This clearly shows my program is trying to free a memory that has not been allocated. How it could have happened?
2. Is it correct to have many malloc_init()?
More information about the freebsd-questions