]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/entry.c
Use IPV6_V6ONLY on IPv6 sockets if available. This way we only get IPv6
[openldap] / servers / slapd / entry.c
index 1ce0a4fbc099dfd39421bab886890ccc4ff5d740..f5829d395af02a3555138d88234b8df301b6e68e 100644 (file)
@@ -24,7 +24,7 @@ static int            emaxsize;/* max size of ebuf                     */
 /*
  * Empty root entry
  */
-const Entry slap_entry_root = { NOID, { 0, "" }, { 0, "" }, NULL, NULL };
+const Entry slap_entry_root = { NOID, { 0, "" }, { 0, "" }, NULL, 0, { 0, "" }, NULL };
 
 int entry_destroy(void)
 {
@@ -71,7 +71,7 @@ str2entry( char *s )
 #endif
 
        /* initialize reader/writer lock */
-       e = (Entry *) ch_malloc( sizeof(Entry) );
+       e = (Entry *) ch_calloc( 1, sizeof(Entry) );
 
        if( e == NULL ) {
 #ifdef NEW_LOGGING
@@ -87,12 +87,6 @@ str2entry( char *s )
 
        /* initialize entry */
        e->e_id = NOID;
-       e->e_name.bv_val = NULL;
-       e->e_name.bv_len = 0;
-       e->e_nname.bv_val = NULL;
-       e->e_nname.bv_len = 0;
-       e->e_attrs = NULL;
-       e->e_private = NULL;
 
        /* dn + attributes */
        vals[1].bv_val = NULL;
@@ -115,8 +109,6 @@ str2entry( char *s )
                }
 
                if ( strcasecmp( type, "dn" ) == 0 ) {
-                       struct berval *pdn = NULL;
-
                        free( type );
 
                        if ( e->e_dn != NULL ) {
@@ -137,22 +129,21 @@ str2entry( char *s )
                        }
 
                        rc = dnPrettyNormal( NULL, &vals[0], &e->e_name, &e->e_nname );
-                       free( vals[0].bv_val );
                        if( rc != LDAP_SUCCESS ) {
 #ifdef NEW_LOGGING
                                LDAP_LOG(( "operation", LDAP_LEVEL_DETAIL1, "str2entry: "
                                        "entry %ld has invalid DN \"%s\"\n",
-                                       (long) e->e_id,
-                                       pdn->bv_val ? pdn->bv_val : "" ));
+                                       (long) e->e_id, vals[0].bv_val ));
 #else
                                Debug( LDAP_DEBUG_ANY, "str2entry: "
                                        "entry %ld has invalid DN \"%s\"\n",
-                                       (long) e->e_id,
-                                       pdn->bv_val ? pdn->bv_val : "", 0 );
+                                       (long) e->e_id, vals[0].bv_val, 0 );
 #endif
                                entry_free( e );
+                               free( vals[0].bv_val );
                                return NULL;
                        }
+                       free( vals[0].bv_val );
                        continue;
                }
 
@@ -314,6 +305,8 @@ entry2str(
        int             i;
        ber_len_t tmplen;
 
+       assert( e != NULL );
+
        /*
         * In string format, an entry looks like this:
         *      dn: <dn>\n
@@ -369,6 +362,11 @@ entry_free( Entry *e )
                e->e_ndn = NULL;
        }
 
+       if ( e->e_bv.bv_val != NULL ) {
+               free( e->e_bv.bv_val );
+               e->e_bv.bv_val = NULL;
+       }
+
        /* free attributes */
        attrs_free( e->e_attrs );
        e->e_attrs = NULL;
@@ -564,7 +562,7 @@ int entry_decode(struct berval *bv, Entry **e)
        BerVarray bptr;
 
        i = entry_getlen(&ptr);
-       x = ch_malloc(i);
+       x = ch_calloc(1, i);
        i = entry_getlen(&ptr);
        x->e_name.bv_val = ptr;
        x->e_name.bv_len = i;
@@ -581,7 +579,7 @@ int entry_decode(struct berval *bv, Entry **e)
            "entry_decode: \"%s\"\n",
            x->e_dn, 0, 0 );
 #endif
-       x->e_private = bv->bv_val;
+       x->e_bv = *bv;
 
        /* A valid entry must have at least one attr, so this
         * pointer can never be NULL
@@ -590,8 +588,10 @@ int entry_decode(struct berval *bv, Entry **e)
        bptr = (BerVarray)x->e_attrs;
        a = NULL;
 
-       while (i = entry_getlen(&ptr)) {
-               struct berval bv = { i, ptr };
+       while ((i = entry_getlen(&ptr))) {
+               struct berval bv;
+               bv.bv_len = i;
+               bv.bv_val = ptr;
                if (a) {
                        a->a_next = (Attribute *)bptr;
                }