Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Null out after free

...

Code Block
bgColor#FFCCCC
size_t num_elements = get_size();
long *buffer = calloc(num_elements, sizeof(long));
if (buffer == NULL) {
  /* handle error condition */
}
/*...*/
free(buffer);
buffer = NULL; 

Compliant Solution

In this compliant solution, the the two arguments num_elements and sizeof(long) are checked before the call to calloc() to determine if wrapping will occur.

...