From: Howard Chu Date: Wed, 7 Nov 2001 01:03:49 +0000 (+0000) Subject: Added schema_destroy() et al to free schema structures on shutdown X-Git-Tag: LDBM_PRE_GIANT_RWLOCK~890 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=5f8058f957b14a7924c6cf3d79dd34e700c396f9;p=openldap Added schema_destroy() et al to free schema structures on shutdown --- diff --git a/servers/slapd/ad.c b/servers/slapd/ad.c index 7ea0734aab..8d77c7ffb7 100644 --- a/servers/slapd/ad.c +++ b/servers/slapd/ad.c @@ -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, diff --git a/servers/slapd/at.c b/servers/slapd/at.c index 5c3cad15c5..e90cc23d8d 100644 --- a/servers/slapd/at.c +++ b/servers/slapd/at.c @@ -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; } diff --git a/servers/slapd/main.c b/servers/slapd/main.c index 785806497e..8d774984e0 100644 --- a/servers/slapd/main.c +++ b/servers/slapd/main.c @@ -542,6 +542,8 @@ stop: #endif slapd_daemon_destroy(); + schema_destroy(); + #ifdef HAVE_TLS ldap_pvt_tls_destroy(); #endif diff --git a/servers/slapd/mr.c b/servers/slapd/mr.c index 5fa82b5231..2ec9ebcc15 100644 --- a/servers/slapd/mr.c +++ b/servers/slapd/mr.c @@ -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, diff --git a/servers/slapd/oc.c b/servers/slapd/oc.c index 6fce72d924..064b553d4b 100644 --- a/servers/slapd/oc.c +++ b/servers/slapd/oc.c @@ -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; } diff --git a/servers/slapd/proto-slap.h b/servers/slapd/proto-slap.h index 4bf68057d6..cd689d5534 100644 --- a/servers/slapd/proto-slap.h +++ b/servers/slapd/proto-slap.h @@ -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)); diff --git a/servers/slapd/schema_init.c b/servers/slapd/schema_init.c index 7d29742259..b421c22690 100644 --- a/servers/slapd/schema_init.c +++ b/servers/slapd/schema_init.c @@ -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(); +} diff --git a/servers/slapd/slap.h b/servers/slapd/slap.h index f2594ddd42..48298e71e0 100644 --- a/servers/slapd/slap.h +++ b/servers/slapd/slap.h @@ -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; diff --git a/servers/slapd/syntax.c b/servers/slapd/syntax.c index b1332ff904..25ca0258ff 100644 --- a/servers/slapd/syntax.c +++ b/servers/slapd/syntax.c @@ -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,