Fixing a problem with dlclose and avahi

In situations where dlopen does not fail but does not load the library,
the handle will be NULL (see issue 3337 in Redmine).

This fix checks if avahi_handle is not NULL before calling dlclose in order
to avoid the agent from crashing unnecessarily.

Once this is integrated into master this needs to be cherry-picked into 3.5.x.

(cherry picked from commit f97edbc7cb4738f7a2932611436301ab3dd1cd2e)