Cleaned up a large number of clang analyzer warnings. Quite a few memory management changes that I've tried to test, but I could have introduced other issues.