Fix a use after free on invalid input.