Fix some issues reported by coverity