Memleaks

Fix a bunch of memory leaks I stumbled upon. Verified with valgrind. Bootstrapped and tested OK.