[Date Prev][Date Next] [Chronological] [Thread] [Top]

(ITS#4437) Removing small memory leak in ldap_initialize

Full_Name: Gregory Ogonowski
Version: 2.3.6
OS: GNU/Linux (Mandriva 2006)
Submission from: (NULL) (


I'm using openldap-2.3.6 provided by Mandriva 2006 and, i have a
little problem with the ldap_initialize function. The following code
produce a tiny memory leak.

#include <stdio.h>
#include <stdlib.h>
#include <ldap.h>
#include <lber.h>

extern char *ldap_int_hostname;

main (int argc, char **argv)
 int version = LDAP_VERSION3;
 struct berval cred, *servcred;

 ldap_initialize (&ld, "ldap://localhost:389";);
 ldap_set_option (ld, LDAP_OPT_PROTOCOL_VERSION, &version);
 cred.bv_val = MYSECRET;
 cred.bv_len = sizeof( MYSECRET ) - 1;
 ldap_sasl_bind_s( ld, MYDN, LDAP_SASL_SIMPLE, &cred, NULL, NULL, &servcred );
 ldap_unbind_ext_s (ld,NULL,NULL);
 free (ldap_int_hostname);
 ldap_int_hostname = NULL;
 return 0;


Valgrind gives the following output:


==19189== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 31 from 2)
==19189== malloc/free: in use at exit: 18 bytes in 1 blocks.
==19189== malloc/free: 133 allocs, 132 frees, 49,813 bytes allocated.
==19189== For counts of detected errors, rerun with: -v
==19189== searching for pointers to 1 not-freed blocks.
==19189== checked 216,372 bytes.
==19189== 18 bytes in 1 blocks are still reachable in loss record 1 of 1
==19189==    at 0x401B43A: malloc (vg_replace_malloc.c:149)
==19189==    by 0x407F2EE: ber_memalloc_x (in /usr/lib/liblber-2.3.so.0.1.1)
==19189==    by 0x407FF48: ber_strdup_x (in /usr/lib/liblber-2.3.so.0.1.1)
==19189==    by 0x4065D0F: (within /usr/lib/libldap-2.3.so.0.1.1)
==19189==    by 0x40661E6: ldap_int_initialize (in
==19189==    by 0x404BE06: ldap_create (in /usr/lib/libldap-2.3.so.0.1.1)
==19189==    by 0x404C240: ldap_initialize (in /usr/lib/libldap-2.3.so.0.1.1)
==19189==    by 0x80485F2: main (test_connect.c:17)
==19189== LEAK SUMMARY:
==19189==    definitely lost: 0 bytes in 0 blocks.
==19189==      possibly lost: 0 bytes in 0 blocks.
==19189==    still reachable: 18 bytes in 1 blocks.
==19189==         suppressed: 0 bytes in 0 blocks.


It seems that the 18 missing bytes are still reachable. Can you tell
me how? There was another small leak on ldap_int_hostname but i could
easily (and cleanly ?) solve this by freeing ldap_int_hostname.

I known that this is a really small problem, this won't make my
application crash, but i would like to solve it. This is long to
explain but it would help me for another program.