Fix use-after-free