Fix some errors detected by coverity.
Fix warnings from merged code.