Fix some of the #1271 valgrind issues.