Misoperation: Release the space on the stack expression: _ block_type_is_valid (phead-> nblockuse)

Source: Internet
Author: User

Misoperation: releasing the space on the stack

Error:

 

Cause:

From the content in the box, we can see that expression: _ block_type_is_valid (phead-> nblockuse) indicates that the memory block type is incorrect. Under what circumstances will this problem occur? For more information, see the following.Code:

 
Void test (vector <int *> * vecptr) {If (vecptr! = NULL) {int nsize = vecptr-> size (); For (INT nindex = 0; nindex <nsize; ++ nindex) {Delete vecptr-> at (nindex ); vecptr-> at (nindex) = NULL;} Delete vecptr; vecptr = NULL ;}}

Call code:

Vector <int *> VEC; int * PTR = NULL; For (INT nindex = 0; nindex <5; nindex ++) {PTR = new int; * PTR = nindex; VEC. push_back (PTR); PTR = NULL;} test (& VEC );

We can see that the VEC variable is applied on the stack and is temporary. When the test function is passed in, the pointer in the vector is released in sequence. This is no problem, but in the last step, we deleted the vector, and this error occurs. the reason is obvious: delete can only delete the memory on the stack, and the memory on the stack does not need to be manually released. Therefore,ProgramThe memory block type is incorrect.

 

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.