]> git.sur5r.net Git - openldap/commitdiff
Added schema_destroy() et al to free schema structures on shutdown
authorHoward Chu <hyc@openldap.org>
Wed, 7 Nov 2001 01:03:49 +0000 (01:03 +0000)
committerHoward Chu <hyc@openldap.org>
Wed, 7 Nov 2001 01:03:49 +0000 (01:03 +0000)
servers/slapd/ad.c
servers/slapd/at.c
servers/slapd/main.c
servers/slapd/mr.c
servers/slapd/oc.c
servers/slapd/proto-slap.h
servers/slapd/schema_init.c
servers/slapd/slap.h
servers/slapd/syntax.c

index 7ea0734aab6d467b774c2a04ea7c126b59c871c1..8d77c7ffb730ce045609c4399b52398304598a78 100644 (file)
@@ -37,6 +37,16 @@ static int ad_keystring(
        return 0;
 }
 
+void ad_destroy( void *in )
+{
+       AttributeDescription *ad = in, *n;
+
+       for (;ad;ad = n) {
+               n = ad->ad_next;
+               ldap_memfree(ad);
+       }
+}
+
 int slap_str2ad(
        const char *str,
        AttributeDescription **ad,
index 5c3cad15c5667774beca4a5a53645227f2d5bb0a..e90cc23d8d9fc5cbf05873c0eb8cb65b5fa0495d 100644 (file)
@@ -171,6 +171,20 @@ 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_attributetype_free((LDAPAttributeType *)a);
+       }
+}
+
 static int
 at_insert(
     AttributeType      *sat,
@@ -207,13 +221,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;
                        }
index 785806497e40c26e6d4c710c51afa2230977aa54..8d774984e042ef1dd2330c3e92f79a6b0897fa7b 100644 (file)
@@ -542,6 +542,8 @@ stop:
 #endif
        slapd_daemon_destroy();
 
+       schema_destroy();
+
 #ifdef HAVE_TLS
        ldap_pvt_tls_destroy();
 #endif
index 5fa82b52319f819c0b8fadef8623372869cd30f6..2ec9ebcc15090d8222362c7e24578197eda60f74 100644 (file)
@@ -55,6 +55,18 @@ mr_find( const char *mrname )
        return( NULL );
 }
 
+void
+mr_destroy( void )
+{
+       MatchingRule *m, *n;
+
+       avl_free(mr_index, ldap_memfree);
+       for (m=mr_list; m; m=n) {
+               n = m->smr_next;
+               ldap_matchingrule_free((LDAPMatchingRule *)m);
+       }
+}
+
 static int
 mr_insert(
     MatchingRule       *smr,
@@ -90,7 +102,7 @@ mr_insert(
                while ( *names ) {
                        mir = (struct mindexrec *)
                                ch_calloc( 1, sizeof(struct mindexrec) );
-                       mir->mir_name = ch_strdup(*names);
+                       mir->mir_name = *names;
                        mir->mir_mr = smr;
                        if ( avl_insert( &mr_index, (caddr_t) mir,
                                         (AVL_CMP) mr_index_cmp,
index 6fce72d924206a895cd64698969a7e6a2e4b42cd..064b553d4b80453dedaadccef102256fc6df5f27 100644 (file)
@@ -279,6 +279,22 @@ oc_add_sups(
        return 0;
 }
 
+void
+oc_destroy( void )
+{
+       ObjectClass *o, *n;
+
+       avl_free(oc_index, ldap_memfree);
+       for (o=oc_list; o; o=n)
+       {
+               n = o->soc_next;
+               ldap_memfree(o->soc_sups);
+               ldap_memfree(o->soc_required);
+               ldap_memfree(o->soc_allowed);
+               ldap_objectclass_free((LDAPObjectClass *)o);
+       }
+}
+
 static int
 oc_insert(
     ObjectClass                *soc,
@@ -309,7 +325,6 @@ oc_insert(
                                 (AVL_DUP) avl_dup_error ) )
                {
                        *err = soc->soc_oid;
-                       ldap_memfree(oir->oir_name);
                        ldap_memfree(oir);
                        return SLAP_SCHERR_DUP_CLASS;
                }
@@ -322,7 +337,7 @@ oc_insert(
                while ( *names ) {
                        oir = (struct oindexrec *)
                                ch_calloc( 1, sizeof(struct oindexrec) );
-                       oir->oir_name = ch_strdup(*names);
+                       oir->oir_name = *names;
                        oir->oir_oc = soc;
 
                        assert( oir->oir_name );
@@ -333,7 +348,6 @@ oc_insert(
                                         (AVL_DUP) avl_dup_error ) )
                        {
                                *err = *names;
-                               ldap_memfree(oir->oir_name);
                                ldap_memfree(oir);
                                return SLAP_SCHERR_DUP_CLASS;
                        }
index 4bf68057d6cfb89af8eea421fb74553bcfd87366..cd689d55348d1f6393a8e9dd959c2dccb4c447f7 100644 (file)
@@ -620,6 +620,13 @@ LDAP_SLAPD_F (int) syn_schema_info( Entry *e );
  * schema.c
  */
 
+LDAP_SLAPD_F (void) oc_destroy LDAP_P(( void ));
+LDAP_SLAPD_F (void) at_destroy LDAP_P(( void ));
+LDAP_SLAPD_F (void) ad_destroy LDAP_P(( void * ));
+LDAP_SLAPD_F (void) mr_destroy LDAP_P(( void ));
+LDAP_SLAPD_F (void) syn_destroy LDAP_P(( void ));
+LDAP_SLAPD_F (void) schema_destroy LDAP_P(( void ));
+
 LDAP_SLAPD_F (ObjectClass *) oc_find LDAP_P((
        const char *ocname));
 
index 7d29742259def647bca6398e17b9ed9e3f9cafe8..b421c22690c75f7da86f0e0b728f7826f391fd0c 100644 (file)
@@ -4726,3 +4726,12 @@ schema_init( void )
        schema_init_done = 1;
        return LDAP_SUCCESS;
 }
+
+void
+schema_destroy( void )
+{
+       oc_destroy();
+       at_destroy();
+       mr_destroy();
+       syn_destroy();
+}
index f2594ddd4276986f915ad9dd0dcbbe16e5b70aba..48298e71e04d85b996d0a7a337a5b9d8af2c69e5 100644 (file)
@@ -369,8 +369,8 @@ typedef struct slap_matching_rule {
 struct slap_attr_desc;
 
 typedef struct slap_attribute_type {
-       char                                    *sat_cname;
        LDAPAttributeType               sat_atype;
+       char                            *sat_cname;
        struct slap_attribute_type      *sat_sup;
        struct slap_attribute_type      **sat_subtypes;
        MatchingRule                    *sat_equality;
index b1332ff90471ed24f7d580b1c866ad663a3bc0bc..25ca0258ff2e2f176ff9ee52ae34ed83086f9cf0 100644 (file)
@@ -66,6 +66,18 @@ syn_find_desc( const char *syndesc, int *len )
        return( NULL );
 }
 
+void
+syn_destroy( void )
+{
+       Syntax *s, *n;
+
+       avl_free(syn_index, ldap_memfree);
+       for (s=syn_list; s; s=n) {
+               n = s->ssyn_next;
+               ldap_syntax_free((LDAPSyntax *)s);
+       }
+}
+
 static int
 syn_insert(
     Syntax             *ssyn,