Client-side memory management depends on the specific LDAP functions. In general, you must release the memory associated with data returned to the client either as an out parameter or as a function return value. However, some functions, such as ldap_err2string, return a pointer to a static buffer, and in that case you should not free the memory associated with the returned data.
The LDAP API supports the following memory management functions. For more information about managing memory for a particular function, see the reference page for that function.
The ldap_memfree function frees memory that was allocated from the LDAP heap. Call this function to free strings, such as the DN returned by ldap_get_dn and the ErrorMessage and MatchedDNs parameters in ldap_parse_result.