A bunch of Coverity fixes.