Fixing a number of big memory leaks.