Fix a use after free bug.