fix use-after-free