Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Referenced Annex J and MEM31-C.

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 or realloc function does not match a pointer earlier returned by calloc, malloc, or realloc, or the space has been deallocated by a call to free or realloc.

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().

...