Fix valgrind/memcheck issues.

Spotted by valgrind