Core analysis caused by delete array

Source: Internet
Author: User

Delete [] PTR raises the core error of Singnal 6 abort, the trace process found writing PTR large amounts of data, throwing out memory out of bounds, destroying the tail data protection of the new array, leading to the time of the delete core.

The problem analysis process wrote a test code, found that some other editor or the nature of the operating system, the new application array is always allocated 2 of the N-square space, such as char* ptr = new char[10] Actually allocated 16 bytes of space, char* ptr2 = new char[ 15] Also allocates 16 bytes of space, while char* PTR3 = new Char[16] Allocates 32 bytes of space, thus speculating that a special character with a byte at the end of the new array is used for protection.

Although the core is found, the memory allocations for the system new and delete are not understood: char* ptr = new Char[10] writes 17 characters to Ptr,delete [] PTR does not core; writes 29 characters to PTR, Delete [] PTR raises the core of signal6 abort, and the head and tail data protection for the memory request is still unclear.

Core analysis caused by delete array

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.