This is the mail archive of the gcc@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]

Segfault with operator delete[] (fwd)


Hello everyone,

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.

I don't understand -- isn't this what one is 'supposed' to do as a 
programmer?  If you grab memory from the free store with operator new, 
you're 'supposed' to call operator delete[] (if it's an array) to put the 
memory back.

Or is that only necessary in C using malloc()/free()?

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 
use malloc()/free(), malloc() seems to work fine, but free() blows 
up.  Even if they are both given the same pointers.  ?? 

Thanks for any 
help.

-- 
Sincerely Yours,
Brian Hart
Department of Physics and Astronomy
4129 Frederick Reines Hall
University of California, Irvine
Irvine, CA 92612-3021
E-Mail: bchart@uci.edu
Phone: (949) 824-6911
URL: http://www.ags.uci.edu/~bchart/



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