Fixed about 18 bug fixes discovered by Coverity static code analyzer.