Merge "Fix bug in error handling that causes segfault"