fix: memory leak plus 2x use-after-free.