]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/at.c
Fixup bdb_entry_release now that entry_decode uses two memory blocks
[openldap] / servers / slapd / at.c
index 63eda95ad2137590f397e81e165f22cfc67106d7..63f5f629c48e3244427508744237f563e64b5e6a 100644 (file)
@@ -95,7 +95,7 @@ at_append_to_list(
        list = *listp;
        if ( !list ) {
                size = 2;
-               list = calloc(size, sizeof(AttributeType *));
+               list = ch_calloc(size, sizeof(AttributeType *));
                if ( !list ) {
                        return -1;
                }
@@ -107,7 +107,7 @@ at_append_to_list(
                        list1++;
                }
                size += 2;
-               list1 = realloc(list, size*sizeof(AttributeType *));
+               list1 = ch_realloc(list, size*sizeof(AttributeType *));
                if ( !list1 ) {
                        return -1;
                }
@@ -144,7 +144,7 @@ at_delete_from_list(
        }
        list[i] = NULL;
        /* Tell the runtime this can be shrinked */
-       list1 = realloc(list, (i+1)*sizeof(AttributeType **));
+       list1 = ch_realloc(list, (i+1)*sizeof(AttributeType **));
        if ( !list1 ) {
                return -1;
        }
@@ -171,6 +171,21 @@ at_find_in_list(
        return -1;
 }
 
+void
+at_destroy( void )
+{
+       AttributeType *a, *n;
+       avl_free(attr_index, ldap_memfree);
+
+       for (a=attr_list; a; a=n) {
+               n = a->sat_next;
+               ldap_memfree(a->sat_subtypes);
+               ad_destroy(a->sat_ad);
+               ldap_pvt_thread_mutex_destroy(&a->sat_ad_mutex);
+               ldap_attributetype_free((LDAPAttributeType *)a);
+       }
+}
+
 static int
 at_insert(
     AttributeType      *sat,
@@ -207,13 +222,12 @@ at_insert(
                while ( *names ) {
                        air = (struct aindexrec *)
                                ch_calloc( 1, sizeof(struct aindexrec) );
-                       air->air_name = ch_strdup(*names);
+                       air->air_name = *names;
                        air->air_at = sat;
                        if ( avl_insert( &attr_index, (caddr_t) air,
                                         (AVL_CMP) attr_index_cmp,
                                         (AVL_DUP) avl_dup_error ) ) {
                                *err = *names;
-                               ldap_memfree(air->air_name);
                                ldap_memfree(air);
                                return SLAP_SCHERR_DUP_ATTR;
                        }
@@ -239,11 +253,19 @@ at_add(
        char                    *cname;
 
        if ( at->at_names && at->at_names[0] ) {
+               int i;
+
+               for( i=0; at->at_names[i]; i++ ) {
+                       if( !slap_valid_descr( at->at_names[i] ) ) {
+                               return SLAP_SCHERR_BAD_DESCR;
+                       }
+               }
+
                cname = at->at_names[0];
+
        } else if ( at->at_oid ) {
                cname = at->at_oid;
        } else {
-               cname = "";
                return SLAP_SCHERR_ATTR_INCOMPLETE;
        }
 
@@ -254,7 +276,9 @@ at_add(
        sat = (AttributeType *) ch_calloc( 1, sizeof(AttributeType) );
        AC_MEMCPY( &sat->sat_atype, at, sizeof(LDAPAttributeType));
 
-       sat->sat_cname = cname;
+       sat->sat_cname.bv_val = cname;
+       sat->sat_cname.bv_len = strlen( cname );
+       ldap_pvt_thread_mutex_init(&sat->sat_ad_mutex);
 
        if ( at->at_sup_oid ) {
                AttributeType *supsat = at_find(at->at_sup_oid);
@@ -328,6 +352,7 @@ at_add(
        }
 
        code = at_insert(sat,err);
+       return code;
 }
 
 #ifdef LDAP_DEBUG