Fix log file handle leaks