Backport a few coverity fixes.