fix various defects reported by coverity