fixing issues from coverity scan 1167937, 1167938, 1167939, 1127248 (http://scan.coverity.com/projects/169?tab=Overview)
Merge pull request #2296 from apavlenko:fix_coverity_scan