Platform SDK: Active Directory, ADSI, and Directory Services

Closing a Connection

When an LDAP client has finished communicating with a server, and all necessary memory cleanup is complete, call ldap_unbind or ldap_unbind_s to unbind from the directory, close the connection, and dispose of the session handle. Call this function whenever you have finished with a connection, even if you haven't explicitly called a bind function to open the connection.

Both ldap_unbind and ldap_unbind_s work synchronously. There is no server response to an unbind operation. Make sure that you do not inadvertently call either unbind function more than once on a session handle because doing so can free resources that you did not intend to release.