Fix some null pointer checks

That fixes issues like CID 1034509 and CID 1034372