Fix an use-after-free