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

Re: Memory leak with ldap_first_attribute()/ldap_next_attribute()?



> 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 */
>  }

So far so good.

>  if (ber)
>   ber_free(ber,0);

This is incorrect.  You should call ldap_msgfree(e), not ber_free.
ldap_msgfree() will correctly free up the chain of results.  I'm
not sure what will happen for the above, but a memory leak is surely
one of the consequences.  

> }
> 
>   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
> 

Randy