Versions Compared

Key

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

...

To correct this problem, the logic in the error handling code should be changed so that it no longer frees list. This change ensures that list is freed only once, in func1 process_list().

Code Block
bgColorccccff
#defineint MIN_SIZE_ALLOWED 10

int  func2(intverify_size(char *list, size_t list_size) {
  if (size < MIN_SIZE_ALLOWED) {
     /* Handle Error Condition */
    return  return-1;
  }

  /* Process list */

  return 0;
}

void func1 process_list(size_t number) {
  char *list = malloc(sizeof(intnumber));
  if (list == NULL) {
    /* Handle Allocation Error */
  }

  func2if (verify_size(list,number);) == -1) {
    /* Handle Error */
  }

  /* Continue Processing list */

  free(list);
}

...