Fix issues to pass all valgrind tests.