Today I met a very depressing bug, which is very strange:
Delete pointer;
When deleting a pointer ProgramA core dump occurs, or it crashes here.
In principle, a new piece of memory is marked at the header or tail of the memory, indicating the size of the block memory.
I guess the pointer must have crossed the border. As a result, the mark at the beginning or the end is damaged, so the delete operation fails.
After checking for several times, no cross-border pointer is found.
In addition, a program is written separately to intentionally destroy the beginning and end of the new memory block. When the result pointer is out of bounds, the program immediately dumps core dump, this indicates that the Linux operating system explicitly prohibits cross-border pointers.
There is no way to use the line-by-line comment method to locate a row.Code. Check the class in which this line of code is located and you still cannot find any problem with this method.
So we extracted this class separately, simulated the same new and delete operations, and finally found that in the close () method, after deleting an internal pointer, it was not assigned a null value, then, close () is called in the destructor, causing a memory to be released twice in a row.
The strange thing is that the memory issue of this class does not occur during the second Delete, but in my own code, when another pointer is deleted, it crashes. I named it heap for destruction. If you do not read the Linux source code, you cannot explain why.
The strange thing is that the Linux server I used for debugging was the 2.4 kernel. When I put the problematic code on the 2.6 kernel server for debugging, there was no problem at all, it seems that the Linux 2.6 kernel is able to fault tolerance the same pointer of two delete operations.
To sum up, note that in the Linux 2.4 kernel operating system, two delete operations with the same memory will cause heap corruption, when you delete other pointers again, core dump may occur or the pointer may be suspended!