Fix a couple of problems found with Valgrind