Check return value of functions that may fail.

Found by Coverity: CID 1109721