Note: Heap Corruption in Linux

Source: Internet
Author: User
Note: Heap Corruption in Linux-general Linux technology-Linux programming and kernel information. For details, refer to the following section. Author: AFU
Today I met a very depressing BUG, which is very strange: delete pointer;

Core dump occurs in the program when a pointer is deleted, or the program 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, and finally locate a line of 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!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.