Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

However, this commonly recommended idiom has problems with zero length allocations. If the value of nsize in this example is 0, the standard allows the option of either returning a null pointer or returning a pointer to an invalid (e.g., zero-length) object. However, the standard does not dictate what the return value should be in either case. In cases where the realloc() function frees the memory but returns a null pointer, execution of this code will result in a double-free when free() is called.

...