Fixing bugs indicated by Coverity