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

Memory leaks using ldap_first_attribute(), ldap_next_attribute(), and ber_free()



Hi All:

I'm trying to avoid memory leaks within an OpenLDAP enabled application
I'm writing but I think I'm messing things up. I'm using libldap 2.0.17.

First of all, about the second argument of ber_free(). ldap_{first,next}_atribute manpage (at http://www.openldap.org/software/man.cgi) says:
"When calling ber_free(3) in this instance, be sure the second argument is 0."
But ber_free() manpage says:
"If freebuf is zero, the internal buffer is not freed"
A little bit confusing, don't you think so?


My real problem is a memory leak when calling ldap_first_attribute():

<codesnippet>
for (ldapattribute = ldap_first_attribute (ldapconn, msg, &ber);
ldapattribute;
ldapattribute = ldap_next_attribute (ldapconn, msg, ber))
{
//ber_free(ber, 1) /* My first try */
ldapvalues = ldap_get_values (ldapconn, msg, ldapattribute);
for (i = 0; ldapvalues[i]; i++)
{
if (!strcmp (ldapattribute,"userPassword"))
pwdbuff = doCpyStrFrom (ldapvalues[i], '}');
}
}
ber_free(ber, 1); /* My second try */
</codesnippet>

Both my first and second try cause memory leak in ldap_first_attribute() (I'm using valgrind).


	Does anybody has a tip or recommendation where I'm messing things up ? :)

Thanks in advance

--

[]'s
Lucas Brasilino
brasilino@recife.pe.gov.br
http://www.recife.pe.gov.br
Emprel -	Empresa Municipal de Informatica (pt_BR)
		Municipal Computing Enterprise (en_US)
Recife - Pernambuco - Brasil
Fone: +55-81-34167078