Coverity Fixes

I'm unsure some of these are correct. Review needed.