This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Segfault with operator delete[]
- From: Nathan Sidwell <nathan at codesourcery dot com>
- To: Brian Hart <bhart at nabhas dot ps dot uci dot edu>
- Cc: gcc-help at gcc dot gnu dot org
- Date: Sat, 23 Aug 2003 15:01:54 +0100
- Subject: Re: Segfault with operator delete[]
- Organization: Codesourcery LLC
- References: <Pine.LNX.4.44.0308222325130.10068-100000@nabhas.ps.uci.edu>
Brian Hart wrote:
Hello:
I am using GCC v2.96 on Red Hat 7.3.
My C++ program ALWAYS seg faults when operator delete[] is called on a
pointer, even though stepping through the code in the debugger reveals not
only the address to be valid, but also it is the same address as that
returned by operator new.
This only happens when calling delete[] on arrays of primitive types
besides char. An example of offending code is:
unsigned long* v = new unsigned long[100];
/* the above succeeds, let's say */
/*snip*/
...
/*snap*/
delete[] v; /*<-- seg fault here; why?? */
v = NULL;
Does this have anything to do with the compiler? Oddly enough, if I
yes, IIRC there was a bug with deleting such arrays (to do with a 'cookie'
telling delete[] how big the array was). I beleive this is fixed in 3.3
(it certainly is in the current development tree.)
The pre 3.0 series compilers are no longer actively maintained.
nathan
--
Nathan Sidwell :: http://www.codesourcery.com :: CodeSourcery LLC
The voices in my head said this was stupid too
nathan@codesourcery.com :: http://www.planetfall.pwp.blueyonder.co.uk