Use-after-free fix