Is this a double free in C?

后端 未结 5 1312
余生分开走
余生分开走 2021-01-13 18:27

Normally, if a pointer is freed twice, it\'s a double free. For example,

char *ptr;
ptr=malloc(5 * sizeof(*ptr));
free(ptr);
free(ptr);

The

5条回答
  •  执笔经年
    2021-01-13 18:42

    Yes as the pointers both point to the same address and so pass the same address to free.

    You can show what the value of the pointer is by printing it

    printf( "%p", ptr);
    

    or look at it in a debugger

提交回复
热议问题