Fix a few errors spotted by coverity