Fix errors reported by valgrind.