Another round of hunting down memory leaks & access-after-freed errors