Fix some issues reported by Coverity scan

Please review.