When an array of derived objects is deleted through its base class, the resulting program seg faults. Could this be caused by destructor iteration with invalid <this> pointers? Reproduced on gcc (GCC) 3.3.3 (cygwin special), egcs-2.91.66 (red hat 6.2), g++ (GCC) 3.3 20030304 (Apple Computer, Inc. build 1495), etc Keylines in the reproducible case below: Component* c = new Component1[2]; delete [] c; Reproducible case: extern "C" int printf(const char *, ...); class Component{ public: Component(); virtual ~Component(); }; Component::Component() { /*printf("Component::Component 0x%x\n",this);*/} Component::~Component() { /*printf("Component::~Component 0x%x\n",this); */} class Component1 : public Component { private: char bytes1[12]; public: Component1(); virtual ~Component1(); }; Component1::Component1() { /*printf("Component1::Component1 0x%x\n",this);*/} Component1::~Component1() { /*printf("Component1::~Component1 0x%x\n",this);*/ } int main() { Component* c = new Component1[2]; delete [] c; return 0; }
*** This bug has been marked as a duplicate of 22609 ***
(In reply to comment #1) > *** This bug has been marked as a duplicate of 22609 *** Sorry about reporting a duplicate. I had looked/searched. Maybe the default settings for the query form should include issues with status RESOLVED (but with resolution <> FIXED; i.e. especially INVALID (and WONTFIX/DUPLICATE). Maybe this would avoid some duplicate bug reports?