Fix some null pointer checks

That fixes issues like CID 1034509 and CID 1034372

Coverity: There may be a null pointer dereference, or else the comparison against null is unnecessary.