This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: problem with new
- From: Eljay Love-Jensen <eljay at adobe dot com>
- To: Arun Prakash <mail2arunprakash at yahoo dot com>, gcc-help at gcc dot gnu dot org
- Date: Wed, 12 Jan 2005 07:01:34 -0600
- Subject: Re: problem with new
- References: <20050112051227.38047.qmail@web50007.mail.yahoo.com>
Hi Arun,
The kind of error you are seeing is often -- but not always -- indicative
of heap corruption, in my experience.
You can get heap corruption by double-deleting a pointer.
You can get heap corruption by using new[] to allocate, but using delete to
deallocate.
You can get heap corruption by using new to allocate, but using delete to
deallocate.
You can get heap corruption by deleting a pointer that was not new'd (not
including NULL).
You can get heap corruption by memory overruns or memory underruns.
You can get heap corruption if you new a pointer from one heap, and attempt
to delete that pointer in a different heap.
You can get heap corruption by a wild pointer.
(I've tried to list these in the order of the most common to least common.)
Unfortunately, when you actually experience the SEGV may be far from the
code that caused the heap to be mucked up.
Fortunately, there are alternative heaps that keep meticulous track of your
heap and perform consistency checks and diagnostic information (often able
to be triggered programmatically). They tend to be significantly slower,
but they can help find heap problems sooner. I don't have any links, but
I'm sure Google can find something.
Also, there are tools that can aid in tracking down these kinds of problems
-- such as electric fence, valgrind, Rational Purify, Parasoft Insure++,
q.v.:
http://www.cs.utexas.edu/users/jpmartin/memCheckers.html
http://users.actcom.co.il/~choo/lupg/tutorials/unix-memory/unix-memory.html
HTH,
--Eljay