fix use-after-free in addFunctionOnce