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

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





--On Thursday, November 04, 2004 2:48 PM -0300 Lucas Brasilino <brasilino@recife.pe.gov.br> wrote:

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.

2.0.17 or 2.2.17?

If it is 2.0.17, OpenLDAP 2.0.x has been deprecated for a long time now, and the last release of OL 2.0 line as I recall was OpenLDAP 2.0.27. In that case, you should really examine upgrading to the 2.2 library set.

If you are using 2.2.17, I suggest reading the code maybe? Not sure. ;)

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?

Hm, I don't see it that way...

This reads to me as:

If you are using ldap_{first,next}_attribute, you don't want to execute the ber_free_buf( ber ) bit in ber_free, but you do want to execute ber_memfree_x( (char *) ber, ber->ber_memctx).

Here's the ber_free code in 2.2.18:

void
ber_free( BerElement *ber, int freebuf )
{
#ifdef LDAP_MEMORY_DEBUG
   assert( ber != NULL );
#endif

   if( ber == NULL ) {
       return;
   }

   if( freebuf ) ber_free_buf( ber );

   ber_memfree_x( (char *) ber, ber->ber_memctx );
}


Unfortunately, I don't have anything to suggest on the rest of your code.

--Quanah

--
Quanah Gibson-Mount
Principal Software Developer
ITSS/Shared Services
Stanford University
GnuPG Public Key: http://www.stanford.edu/~quanah/pgp.html