C + + Memory error pooling

Source: Internet
Author: User

1. A heap corruption detected error occurred in the memory of the free application.

Heap corruption. When the input exceeds the amount of pre-allocated space, it overwrites a storage area after that space, which is called the heap corruption. This is often also used as a means of hacking, because if the storage area after the space is more important data, you can use the heap corruption to modify the data, of course, the consequences are conceivable.

Char " Hello " ;     int  Array_length = strlen (a);     char* p = NULL;     = (char*) malloc (sizeof(char) *array_length);    strcpy (P, a);    Free (p);


The following is normal and this error does not occur.

Char " Hello " ;     // ' 0 '    int  Array_length = strlen (a) +1;     char* p = NULL;     = (char*) malloc (sizeof(char) *array_length);    strcpy (P, a);    Free (p);     = NULL;

When declaring a character array, the number in [] should be the number of characters in the array, including '/0 '

such as char p[5] = "dddd";

The actual is: ' d ' d ' d ' d '/0 '.

If char p[5] = "DDDDD";

Compile error, prompting out of bounds.

C + + Memory error pooling

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.