[Core] Fix a couple issues detected by valgrind.