memory corruption

2020-04-12 09:49发布

i was running a small c program:

#include<stdio.h>
int main()
{
char *p;
p = (char *)malloc(10);
free(p);
free(p);
free(p);
printf("\npointer is freed!!\n");
}

basically i am freeing the memory which has already been freed. i think should result in a core dump!!is it not so?

but it is printing the

pointer is freed!!

am i wrong some where?

7条回答
Anthone
2楼-- · 2020-04-12 10:54

Heap corruption need not cause the problem immediately. It could so happen that the freed memory ( or part of the memory) is used to allocat some other structure and then it might cause problem. freeing memory more than once is always UB (undefined) and should not be done even if you don't see evil effects at that moment.

查看更多
登录 后发表回答