Fix issues revealed by Clang Static Analyzer

One issue was a legitimate leak and has been fixed. The other two were false positives for which workarounds have been provided and a radar issue has been opened.