fixing issues from coverity scan

1167937, 1167938, 1167939, 1127248
(http://scan.coverity.com/projects/169?tab=Overview)