Fix lots of memory leaks