BerElement argument per latest IETF ldapext draft c api spec.
That is, caller is solely responsible for freeing the BerElement
allocated and returned by ldap_first_attribute.
Update man pages accordingly.
Update applications accordingly.
{
char *a, *dn, *ufn, tmpfname[ 64 ];
int i, j, notascii;
- BerElement *ber;
+ BerElement *ber = NULL;
struct berval **bvals;
FILE *tmpfp;
ber_bvecfree( bvals );
}
}
+
+ if( ber != NULL ) {
+ ber_free( ber, 0 );
+ }
}
{
int idx;
char **rdns;
- BerElement *cookie;
register LDAPMessage *ep;
register char *ap;
printf(" Done clearing entry\n");
#endif
for (ep = ldap_first_entry(ld, s); ep != NULL; ep = ldap_next_entry(ld, ep)) {
+ BerElement *cookie = NULL;
#ifdef DEBUG
if (debug & D_PARSE)
printf(" Determining DN and name\n");
}
add_value(&(Entry.attrs[idx]), ep, ap);
}
+
+ if( cookie != NULL ) {
+ ber_free( cookie, 0 );
+ }
}
#ifdef DEBUG
if (debug & D_PARSE)
be passed to subsequent calls to
.B ldap_next_attribute()
and is used used
-to effectively step through the entry's attributes. This pointer
-is freed by
-.B ldap_next_attribute()
-when there are no more attributes (that
-is, when
-.B ldap_next_attribute()
-returns NULL). Otherwise, the caller is
-responsible for freeing the BerElement pointed to by \fIberptr\fP when
-it is no longer needed by calling
+to effectively step through the entry's attributes. The caller is
+solely responsible for freeing the BerElement pointed to by \fIberptr\fP
+when it is no longer needed by calling
.BR ber_free (3).
When calling
.BR ber_free (3)
.SH NOTES
The
.B ldap_first_attribute()
-routine dyanamically allocated memory that may need to
-be freed by the caller via
-.BR ber_free (3).
+routine dyanamically allocated memory that must be freed by the caller via
+.BR ber_free (3).
.SH SEE ALSO
.BR ldap(3),
.BR ldap_first_entry(3),
Debug( LDAP_DEBUG_TRACE, "ldap_first_attribute\n", 0, 0, 0 );
if ( (*ber = ldap_alloc_ber_with_options( ld )) == NULLBER ) {
+ *ber = NULL;
return( NULL );
}
== LBER_ERROR ) {
ld->ld_errno = LDAP_DECODING_ERROR;
ber_free( *ber, 0 );
+ *ber = NULL;
return( NULL );
}
if ( ber_scanf( ber, "{sx}", ld->ld_attrbuffer, &len )
== LBER_ERROR ) {
ld->ld_errno = LDAP_DECODING_ERROR;
- ber_free( ber, 0 );
+ /* ber_free( ber, 0 ); *//* don't free the BerElement */
return( NULL );
}
static void
print_search_entry( LDAP *ld, LDAPMessage *res )
{
- BerElement *ber;
- char *a, *dn, *ufn;
- struct berval **vals;
- int i;
LDAPMessage *e;
for ( e = ldap_first_entry( ld, res ); e != NULLMSG;
- e = ldap_next_entry( ld, e ) ) {
+ e = ldap_next_entry( ld, e ) )
+ {
+ BerElement *ber = NULL;
+ char *a, *dn, *ufn;
+
if ( e->lm_msgtype == LDAP_RES_SEARCH_RESULT )
break;
free( ufn );
for ( a = ldap_first_attribute( ld, e, &ber ); a != NULL;
- a = ldap_next_attribute( ld, e, ber ) ) {
+ a = ldap_next_attribute( ld, e, ber ) )
+ {
+ struct berval **vals;
+
printf( "\t\tATTR: %s\n", a );
if ( (vals = ldap_get_values_len( ld, e, a ))
== NULL ) {
printf( "\t\t\t(no values)\n" );
} else {
+ int i;
for ( i = 0; vals[i] != NULL; i++ ) {
int j, nonascii;
ber_bvecfree( vals );
}
}
+
+ if(ber != NULL) {
+ ber_free( ber, 0 );
+ }
}
if ( res->lm_msgtype == LDAP_RES_SEARCH_RESULT
ldap_value_free( vals );
}
}
+
+ if( ber != NULL) {
+ ber_free( ber, 0 );
+ }
} else {
for ( rowp = ldap_first_tmplrow( tmpl );
NONFATAL_LDAP_ERR( err ) && rowp != NULLTMPLITEM;