Fix small memory leak incase of errors