malloc: *** error for object 0x165060: pointer being freed was not allocated?

后端 未结 6 1019
温柔的废话
温柔的废话 2020-12-31 10:18

I have an application in which i have some videos and audios and some inapp purchases.all r great in simulator and working perfectly.But yesterday i have created an applicat

6条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-31 11:10

    I got this kind of error when your trying to call free on a pointer that the address is not at start of block. For example:

     1 #include 
     2 #include 
     3 
     4 int main()
     5 {
     6 
     7    int a; // some integers
     8    int *pi;     // a pointer to an integer
     9    pi =(int*) malloc( 1*sizeof(int) );
    10 
    11    a = 5;
    12    pi = &a; // pi points to a
    13    pi++; // pi is not anymore at start
    14    free(pi);
    15 
    16    printf("at the end, we are alived \n"); // this will not be printed
    17  
    18    return 0;
    19 }
    

提交回复
热议问题