当您尝试释放(c)中已经释放的内存会发生什么? [英] What happens when you try to free() already freed memory in c?

查看:144
本文介绍了当您尝试释放(c)中已经释放的内存会发生什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如:

char * myString = malloc(sizeof(char)*STRING_BUFFER_SIZE);
free(myString);
free(myString);

是否有这样做的任何不良副作用?

Are there any adverse side effects of doing this?

推荐答案

下面的篇章,段落。

如果参数[到免费功能]不匹配前面返回的指针释放calloc 的malloc
  的realloc 函数,或者如果空间已释放通过调用免费 realloc的
  该行为是不确定的。 ( ISO 9899:1999 - 编程语言 - ç,第7.20.3.2)

If the argument [to the free function] does not match a pointer earlier returned by the calloc, malloc, or realloc function, or if the space has been deallocated by a call to free or realloc, the behavior is undefined. (ISO 9899:1999 - Programming languages — C, Section 7.20.3.2)

这篇关于当您尝试释放(c)中已经释放的内存会发生什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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