]> git.sur5r.net Git - openldap/commitdiff
Some malloc tweaks for for print_vals
authorHoward Chu <hyc@openldap.org>
Fri, 8 Feb 2002 06:54:04 +0000 (06:54 +0000)
committerHoward Chu <hyc@openldap.org>
Fri, 8 Feb 2002 06:54:04 +0000 (06:54 +0000)
servers/slapd/repl.c

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