fixed possible NULL pointer dereference in agent