Prevent use-after-free