Refactor ldap_send() to handle closing the connection on errors.