Versions Compared

Key

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

...

Code Block
bgColor#FFCCCC
int main(int argc, char const *argv[]) {
  char *buff;

  buff = (char *)malloc(BUFSIZEBUFSIZ);
  if (!buff) {
     /* handle error condition */
  }
  /* ... */
  free(buff);
  /* ... */
  strncpy(buff, argv[1], BUFSIZEBUFSIZ-1);
}

Compliant Solution

Do not free the memory until it is no longer required.

Code Block
bgColor#ccccff
int main(int argc, char const *argv[]) {
  char *buff;

  buff = (char *)malloc(BUFSIZEBUFSIZ);
  if (!buff) {
     /* handle error condition */
  }
  /* ... */
  strncpy(buff, argv[1], BUFSIZEBUFSIZ-1);
  /* ... */
  free(buff);
}

...