1 comment

[ 3.1 ms ] story [ 12.3 ms ] thread
I'm curious, when there is code like:

  case let matches: [][]regex::capture =>
   defer regex::free_matches(matches);
is there a gap between those two statements where memory for matches has been allocated in regex but won't be freed because the defer hasn't happened?

For example, in Python I'd write:

  fd = None
  try:
    fd = os.open(...)
    (do stuff with fd)
  except Exception, err:
    (report err)
  finally:
    if fd is not None:
      os.close(fd)
so that there is no gap. It might be tempting to write:

  try:
    fd = os.open(...)
    (do stuff with fd)
  except Exception, err:
    (report err)
  finally:
    os.close(fd)
That works if (do stuff with fd) fails but blows up with fd uninitialized in os.close if os.open fails.