Fix a memory leak on error