Bunch of cppcheck fixes.

I leave these for review and merging. If desired, I'll commit some more next week.