Fix a bunch of memory leaks