内存损坏 [英] memory corruption

查看:97
本文介绍了内存损坏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行一个小型C程序:

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?

但它正在打印

pointer is freed!!

我在某些地方错了吗?

推荐答案

根据手册页,如果以前已经调用过free(ptr),则会发生未定义的行为."

As per the man page, "if free(ptr) has already been called before, undefined behavior occurs."

它不需要炸毁; 不做任何事情"是完全可以接受的不确定行为.也是鼻恶魔.不要依赖它.

It doesn't need to blow up; "not doing anything" is perfectly acceptable undefined behaviour. Also are nasal demons. Don't rely on it.

这篇关于内存损坏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆