←back to thread

271 points mithcs | 1 comments | | HN request time: 1.069s | source
1. kazinator ◴[] No.45960494[source]

  // The Old Way (don't do this)
  char* include_pattern = NULL;
  if (optarg) {
      include_pattern = strdup(optarg);
  }
  // ...200 lines later...
  if (some_error) {
      if (include_pattern) free(include_pattern); // Did I free it? Did I??
      return 1;
Nope!

  // ...200 lines later...
  // common return block

  out:
  free(include_pattern);  // free(NULL) allowed since before 1989 ANSI C
  return result;