Fix a potential nullptr dereference