Fix various issues detected by Coverity.