Fix a memory leak in an error path