Use LDAP memory management functions instead of Asterisk's

When MALLOC_DEBUG is enabled with res_config_ldap, issues (munmap_chunk:
invalid pointer errors) can occur as the memory is being allocated with
Asterisk's wrappers around malloc/calloc/free/strdup, as opposed to the
LDAP library's wrappers.

This patch uses the LDAP library's wrappers where appropriate, so that
compiling with MALLOC_DEBUG doesn't cause more problems than it solves.

Note that the patch listed below was modified slightly for this commit
to account for some additional memory allocation/deallocations.

(closes issue ASTERISK-17386)
Reported by: John Covert
Tested by: Andrew Latham
patches:
  issue18789-1.8-r316873.patch uploaded by seanbright (License 5060)


git-svn-id: http://svn.asterisk.org/svn/asterisk/branches/1.8@385190 f38db490-d61c-443f-a65b-d21fe96a405b