[Date Prev][Date Next]
[Chronological]
[Thread]
[Top]
Re: Memory leak with ldap_first_attribute()/ldap_next_attribute()?
> You need to do a ldap_memfree on each attribute returned by
> ldap_first_attribute or ldap_next_attribute
>
> -Steve
No, no, this is wrong. You need to free the result, and do nothing with the
ber values until the end.
Ldap_msgfree(LDAPMessage *lm) frees everything associated with a result,
including all the attribute values -- they are not copied when you walk
through the attributes and you should not try to free anything within a
result.
However, I stand corrected, and agree that the code
if (ber)
ber_free(ber,0);
}
*is* needed (I was recalling an old version of ldap_next_attribute, which
used to free ber when it hit the end of the loop).
There is one unlikely case in ldap_first_attribute which appears to be
a leak:
if ( ber_pvt_ber_remaining( ber ) == 0 ) {
assert( len == 0 );
return NULL;
}
assert( len != 0 );
This occurs before the *berout = ber, so it should probably have a
ber_free(ber, 0) inserted before the return. Perhaps the assert()
makes it moot.
I'm probably overlapping replies with Kurt.
Randy
>
> >>> Bertrand Croq <bcroq@virtual-net.fr> 04-Oct-00 11:06:48 AM >>>
> Hi,
> after some hours of debugging, I have been able to write a simple code
> that produces memory leaks on my system (OpenLDAP 2.0.4 on Linux Debian
> 2.2 (x86)):
>
> {
> [... ldap_search() ...]
> for (a=ldap_first_attribute(ld, e, &ber);
> a!=NULL;
> a=ldap_next_attribute(ld, e, ber)) {
> /* nothing in the body */
> }
> if (ber)
> ber_free(ber,0);
> }
>
> When I comment out this loop or when ldap_next_attribute() is not
> called (when there is no attribute), I don't get any memory leak... This
> looks like a problem already posted to this mailing list ("Possible
> memory leak in libldap.a/liblber.a" by Ashley Neal Hornbeck on 21 Jan
> 1999). Does anybody knows what/where the problem can be?
>
> Thanks.
> --
> Bertrand Croq - VIRTUAL NET (http://www.virtual-net.fr)
> 80, avenue des Buttes de Coesmes - 35700 RENNES
> tel: +33 2 23 21 06 30 - fax: +33 2 99 38 16 85