/* $OpenLDAP$ */
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
*
- * Copyright 1998-2004 The OpenLDAP Foundation.
+ * Copyright 1998-2005 The OpenLDAP Foundation.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
#include <ac/string.h>
#include <ac/time.h>
-#include "ldap_pvt.h"
#include "slap.h"
#include "lutil.h"
}
an = ch_realloc( an, ( i + j + 1 ) * sizeof( AttributeName ) );
+ BER_BVZERO( &an[i + j].an_name );
anew = an + i;
for ( s = ldap_pvt_strtok( str, brkstr, &lasts );
s != NULL;
adname.bv_val = &anew->an_name.bv_val[1];
slap_bv2ad(&adname, &anew->an_desc, &text);
if ( !anew->an_desc ) {
- free( an );
- free( str );
- /*
- * overwrites input string
- * on error!
- */
- strcpy( in, s );
- return NULL;
+ goto reterr;
}
} break;
ocname.bv_val = &anew->an_name.bv_val[1];
anew->an_oc = oc_bvfind( &ocname );
if ( !anew->an_oc ) {
- free( an );
- free( str );
- /*
- * overwrites input string
- * on error!
- */
- strcpy( in, s );
- return NULL;
+ goto reterr;
}
if ( anew->an_name.bv_val[0] == '!' ) {
/* old (deprecated) way */
anew->an_oc = oc_bvfind( &anew->an_name );
if ( !anew->an_oc ) {
- free( an );
- free( str );
- /* overwrites input string on error! */
- strcpy( in, s );
- return NULL;
+ goto reterr;
}
}
}
anew->an_name.bv_val = NULL;
free( str );
return( an );
+
+reterr:
+ for ( i = 0; an[i].an_name.bv_val; i++ ) {
+ free( an[i].an_name.bv_val );
+ }
+ free( an );
+ /*
+ * overwrites input string
+ * on error!
+ */
+ strcpy( in, s );
+ free( str );
+ return NULL;
}
char **anlist2charray_x( AttributeName *an, int dup, void *ctx )
attrs = anlist2charray( anlist, 1 );
for ( i = 0; anlist[i].an_name.bv_val; i++ ) {
- if ( oc = anlist[i].an_oc ) {
+ if ( ( oc = anlist[i].an_oc ) ) {
for ( j = 0; oc->soc_required && oc->soc_required[j]; j++ ) ;
k += j;
for ( j = 0; oc->soc_allowed && oc->soc_allowed[j]; j++ ) ;
attrs = (char **) ch_realloc( attrs, (i + k + 1) * sizeof( char * ));
for ( i = 0; anlist[i].an_name.bv_val; i++ ) {
- if ( oc = anlist[i].an_oc ) {
+ if ( ( oc = anlist[i].an_oc ) ) {
for ( j = 0; oc->soc_required && oc->soc_required[j]; j++ ) {
attrs[n++] = ch_strdup(
oc->soc_required[j]->sat_cname.bv_val );
}
}
- attrs = (char **) ch_realloc( attrs, (i+1) * sizeof( char * ));
+ if ( i != n )
+ attrs = (char **) ch_realloc( attrs, (i+1) * sizeof( char * ));
return attrs;
}
while ( fgets( lcur, LBUFSIZ, fp ) != NULL ) {
char *str, *s, *next;
const char *delimstr = brkstr;
- if (c = strchr( lcur, '\n' )) {
+ if ( ( c = strchr( lcur, '\n' ) ) ) {
if ( c == line ) {
*c = '\0';
} else if ( *(c-1) == '\r' ) {