fix bugs indicated by coverity