Fixes a few misc memory management problems (valgrind reports).