This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: problem with new


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]