Don't dereference null pointers

Potential crash place. Hard to reproduce.