Hi!
Somtimes, when I'm testing a program made it with C/C++, this one crashes with a glibc message that says:
"Double free or corruption"
I solve this, usually, commenting any line in any destructor helped by gdb. Well, I suposse that this occurs when I'm setting free memory that the system already set free, it's true? How can I know when I must set free memory and when no?
Thanks and excuse my english.
C++ and destructors
The issue is that you didn't follow the "rule of three". You need a copy constructor and operator= in there to handle the cases where you copied the class. Or use a "smart pointer" instead of a raw pointer. It isn't the delete that is bad. It is the fact that you aren't properly copying your pointed to objects.
You always have to free any memory you allocate on the heap, or it is a leak.
Quote:
How can I know when I must set free memory and when no?
You always have to free any memory you allocate on the heap, or it is a leak.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement