fixed defects from coverity.com
fixed defects from Xcode
Merge pull request #2393 from ilya-lavrenov:coverity