Fix buffer leak on error.