Fix potential null pointer dereference