*** glibc detected *** double free or corruption - ERROR
This isn't a question, but I thought it might be helpful as I have found quite a few posts on the net about this problem and I have spent the last hour and a half fixing it.
PROBLEM:
vector<MyClass> myVector;
for(int i = 1; i != 11 ; ++i)
{
MyClass* myObject = new MyClass();
myVector.push_back(*myObject);
delete myObject;
}
======
It compiles fine, then bombs out after a few loops saying
" *** glibc detected *** double free or corruption "
and dumps a load of junk to the terminal.
SOLUTION:
There are missing or incorrect copy or assignment operators for the MyClass class, or some of the sub-classes of MyClass. Make sure that for every class you define:
MyClass(const MyClass& object);
MyClass& operator=(const MyClass& rhs);
Telling the program exactly how to deep copy objects, if you don't do this then it is only the pointers that get copied and this leads to big problems. (Also remember to make sure that your destructor properly deletes all pointers.
======
Hope that helps someone.
Last edited by bandwidthjunkie; 03-19-2007 at 09:31 AM.
|