Fix a few memory leaks in the CLI found by AddressSanitizer.