Wiki Markup |
---|
As noted in [undefined behavior 169| CC. Undefined Behavior#ub_169] of Annex J of \[[ISO/IEC 9899-1999| AA. C References#ISO/IEC 9899-1999]\], the behavior a program is [undefined | BB. Definitions#undefined behavior] when |
the pointer argument to the
free
orrealloc
function does not match a pointer earlier returned bycalloc
,malloc
, orrealloc
, or the space has been deallocated by a call tofree
orrealloc
.
Freeing memory that is not allocated dynamically can lead to serious errors similar to those discussed in MEM31-C. Free dynamically allocated memory exactly once. The specific consequences of this error depend on the compiler implementation, but they range from nothing to abnormal program termination. Regardless of the compilerimplementation, avoid calling free()
on anything other than a pointer returned by a dynamic-memory allocation function, such as malloc()
, calloc()
, or realloc()
.
...