Avoid some null pointer dereferences.

Found by clang's scan-build.