当你尝试 free() 已经在 c 中释放内存时会发生什么? [英] What happens when you try to free() already freed memory in c?
本文介绍了当你尝试 free() 已经在 c 中释放内存时会发生什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
例如:
char * myString = malloc(sizeof(char)*STRING_BUFFER_SIZE);
free(myString);
free(myString);
这样做是否有任何不利的副作用?
Are there any adverse side effects of doing this?
推荐答案
这是章节和诗句.
如果 [to the free
function] 的参数与 calloc
、malloc
或 malloc
先前返回的指针不匹配realloc
函数,或者如果空间已通过调用 free
或 realloc
释放,行为未定义.(ISO 9899:1999 - 编程语言 — C,第 7.20.3.2 节)
If the argument [to the
free
function] does not match a pointer earlier returned by thecalloc
,malloc
, orrealloc
function, or if the space has been deallocated by a call tofree
orrealloc
, the behavior is undefined. (ISO 9899:1999 - Programming languages — C, Section 7.20.3.2)
这篇关于当你尝试 free() 已经在 c 中释放内存时会发生什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文