Fix possible NULL pointer dereference