Check return value when it make sense.

Fixes CID #965890, #965892, #965893, #965894, #965898, #1084351
Remove dead conditionals

Fixes CID #965943 #965949
Fix integer overflow

Fixes CID #966079, #966078
Remove unused pointers

Fixes #966530, #966532
Fix uninitialized scalar field

CID #966282, #966283, #966284, #966285, #966286, #966287, #966316, #966343