memory corruption

前端 未结 7 1041
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-21 19:31

i was running a small c program:

#include
int main()
{
char *p;
p = (char *)malloc(10);
free(p);
free(p);
free(p);
printf(\"\\npointer is freed!!\         


        
7条回答
  •  借酒劲吻你
    2021-01-21 19:56

    It depend on the implementation of your OS (linux, windows...) who implement this function. Their behaviors may be different depending on the OS (undefined behavior), so you must not rely on them and you must free only one time all allocated memory in you program.

    EDIT: it is not part of the OS but of the standard library which differ depending on the OS.

提交回复
热议问题