Fix a number of memory leaks (#204)