Various fixes to issues detected by Coverity Scan. Notes about the
fixes are found there. Probably none of these were show stoppers
but we're better off with the fixes in place.