Fix null pointer dereference