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