agent: Eliminate the possible use of NULL pointer

Fixes #717