Fix a variety of memory leaks