openldap: check ld structure before passing it to ldap_unbind()