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

ldap_first_attribute and ldap_next_attribute and ber_free

The documentation for ldap_first_attribute and ldap_next_attribute
says that they free the ber pointer when there are no more attributes.
Below is ldap_next_attribute (from version 1.2):

char *
ldap_next_attribute( LDAP *ld, LDAPMessage *entry, BerElement *ber )
        long    len;

        Debug( LDAP_DEBUG_TRACE, "ldap_next_attribute\n", 0, 0, 0 );

        /* skip sequence, snarf attribute type, skip values */
        len = LDAP_MAX_ATTR_LEN;
        if ( ber_scanf( ber, "{sx}", ld->ld_attrbuffer, &len )
            == LBER_ERROR ) {
                ld->ld_errno = LDAP_DECODING_ERROR;
                ber_free( ber, 0 );
                return( NULL );

        return( ld->ld_attrbuffer );

I would read this to say that ber_free is only freed when there
is an LDAP_DECODING_ERROR.  The only way the calling application
would be able to tell the difference is to check ld->ld_errno.

So is it guaranteed that if there is not a ber_scanf error, then
ld->ld_attrbuffer != NULL, and that an LDAP_DECODING_ERROR indicates
the end of the attributes (ie. not really an error per se)?