Clang static analysis 20140827

Some changes clang's analyzer found.

I haven't gone through all of the reports yet, but feel free to cherry-pick if the branch isn't acceptable as a whole.