fix use-after-free bug in loader