Some malloc tweaks for for print_vals

This commit is contained in:
Howard Chu 2002-02-08 06:54:04 +00:00
parent f50b75f0c2
commit f4989b6210

View File

@ -284,8 +284,8 @@ replog1(
fprintf( fp, "replace: %s\n", type ); fprintf( fp, "replace: %s\n", type );
break; break;
} }
if ( ml->sml_bvalues )
print_vals( fp, &ml->sml_desc->ad_cname, ml->sml_bvalues ); print_vals( fp, &ml->sml_desc->ad_cname, ml->sml_bvalues );
fprintf( fp, "-\n" ); fprintf( fp, "-\n" );
} }
break; break;
@ -324,15 +324,18 @@ print_vals(
struct berval *type, struct berval *type,
struct berval *bv ) struct berval *bv )
{ {
int len; int i, len;
char *buf, *bufp; char *buf, *bufp;
for ( ; bv && bv->bv_val; bv++ ) for ( i = 0, len = 0; bv && bv[i].bv_val; i++ ) {
{ if ( bv[i].bv_len > len )
len = type->bv_len; len = bv[i].bv_len;
len = LDIF_SIZE_NEEDED( len, bv->bv_len ) + 1; }
buf = (char *) ch_malloc( len );
len = LDIF_SIZE_NEEDED( type->bv_len, len ) + 1;
buf = (char *) ch_malloc( len );
for ( ; bv && bv->bv_val; bv++ ) {
bufp = buf; bufp = buf;
ldif_sput( &bufp, LDIF_PUT_VALUE, type->bv_val, ldif_sput( &bufp, LDIF_PUT_VALUE, type->bv_val,
bv->bv_val, bv->bv_len ); bv->bv_val, bv->bv_len );
@ -340,6 +343,6 @@ print_vals(
fputs( buf, fp ); fputs( buf, fp );
free( buf );
} }
free( buf );
} }