Check return value when it make sense.

Fixes CID #965890, #965892, #965893, #965894, #965898, #1084351