Is this a double free in C?

后端 未结 5 1314
余生分开走
余生分开走 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:59

    Yep. A double free is when you attempt to free a memory block that has already been freed. Both ptr and ptr1 are pointing to the same memory block, so the second call to free is attempting to free a memory block that is already freed.

提交回复
热议问题