]> git.sur5r.net Git - openldap/commitdiff
ITS#7906,#7923 Don't free configinfo in _db_close
authorHoward Chu <hyc@openldap.org>
Wed, 20 Aug 2014 20:40:19 +0000 (13:40 -0700)
committerHoward Chu <hyc@openldap.org>
Wed, 20 Aug 2014 20:49:37 +0000 (13:49 -0700)
servers/slapd/overlays/auditlog.c
servers/slapd/overlays/constraint.c
servers/slapd/overlays/dds.c
servers/slapd/overlays/dyngroup.c
servers/slapd/overlays/pcache.c
servers/slapd/overlays/refint.c
servers/slapd/overlays/seqmod.c
servers/slapd/overlays/slapover.txt
servers/slapd/overlays/unique.c

index 51578e2858aa1520a60495d88c2711a1b0847b15..ba695308bb68edc43e5cb1f410c91808ca4d1d42 100644 (file)
@@ -199,20 +199,6 @@ auditlog_db_init(
        return 0;
 }
 
-static int
-auditlog_db_close(
-       BackendDB *be,
-       ConfigReply *cr
-)
-{
-       slap_overinst *on = (slap_overinst *)be->bd_info;
-       auditlog_data *ad = on->on_bi.bi_private;
-
-       free( ad->ad_logfile );
-       ad->ad_logfile = NULL;
-       return 0;
-}
-
 static int
 auditlog_db_destroy(
        BackendDB *be,
@@ -223,6 +209,7 @@ auditlog_db_destroy(
        auditlog_data *ad = on->on_bi.bi_private;
 
        ldap_pvt_thread_mutex_destroy( &ad->ad_mutex );
+       free( ad->ad_logfile );
        free( ad );
        return 0;
 }
@@ -232,7 +219,6 @@ int auditlog_initialize() {
 
        auditlog.on_bi.bi_type = "auditlog";
        auditlog.on_bi.bi_db_init = auditlog_db_init;
-       auditlog.on_bi.bi_db_close = auditlog_db_close;
        auditlog.on_bi.bi_db_destroy = auditlog_db_destroy;
        auditlog.on_response = auditlog_response;
 
index 4e8b13dd6cd93a6539defe8816eecf6e4a9a2914..e101cd86568bc3a31ab1cf761adfa7bc0864d196 100644 (file)
@@ -1161,7 +1161,7 @@ mod_violation:
 }
 
 static int
-constraint_close(
+constraint_destroy(
        BackendDB *be,
        ConfigReply *cr )
 {
@@ -1186,7 +1186,7 @@ constraint_initialize( void ) {
        int rc;
 
        constraint_ovl.on_bi.bi_type = "constraint";
-       constraint_ovl.on_bi.bi_db_close = constraint_close;
+       constraint_ovl.on_bi.bi_db_destroy = constraint_destroy;
        constraint_ovl.on_bi.bi_op_add = constraint_add;
        constraint_ovl.on_bi.bi_op_modify = constraint_update;
        constraint_ovl.on_bi.bi_op_modrdn = constraint_update;
index f6c30951b0754e016a59e9bfdfbead52d3752ef8..1984998c587dca688c9abadbf7e339782dc541d9 100644 (file)
@@ -1784,6 +1784,7 @@ dds_db_close(
                }
                ldap_pvt_runqueue_remove( &slapd_rq, di->di_expire_task );
                ldap_pvt_thread_mutex_unlock( &slapd_rq.rq_mutex );
+               di->di_expire_task = NULL;
        }
 
        (void)entry_info_unregister( dds_entry_info, (void *)di );
index ed23366dae0b4a30612c92e81cf2fe1152316055..bcae36ccb5e4de0365dca11ec58a85d8f09dccfd 100644 (file)
@@ -181,7 +181,7 @@ dyngroup_response( Operation *op, SlapReply *rs )
 }
 
 static int
-dyngroup_close(
+dyngroup_destroy(
        BackendDB *be,
        ConfigReply *cr
 )
@@ -207,7 +207,7 @@ int dyngroup_initialize() {
        int code;
 
        dyngroup.on_bi.bi_type = "dyngroup";
-       dyngroup.on_bi.bi_db_close = dyngroup_close;
+       dyngroup.on_bi.bi_db_destroy = dyngroup_destroy;
        dyngroup.on_response = dyngroup_response;
 
        dyngroup.on_bi.bi_cf_ocs = dgroupocs;
index 7956a67442f252d4f53ca5b8c0fd59440b27c0e9..291dddf0f23bded80b13fbe34b41dab5875cc0ca 100644 (file)
@@ -4780,7 +4780,7 @@ pcache_db_close(
        cache_manager *cm = on->on_bi.bi_private;
        query_manager *qm = cm->qm;
        QueryTemplate *tm;
-       int i, rc = 0;
+       int rc = 0;
 
        /* stop the thread ... */
        if ( cm->cc_arg ) {
@@ -4790,6 +4790,7 @@ pcache_db_close(
                }
                ldap_pvt_runqueue_remove( &slapd_rq, cm->cc_arg );
                ldap_pvt_thread_mutex_unlock( &slapd_rq.rq_mutex );
+               cm->cc_arg = NULL;
        }
 
        if ( cm->save_queries ) {
@@ -4861,10 +4862,35 @@ pcache_db_close(
        cm->db.be_limits = NULL;
        cm->db.be_acl = NULL;
 
-
        if ( cm->db.bd_info->bi_db_close ) {
                rc = cm->db.bd_info->bi_db_close( &cm->db, NULL );
        }
+
+#ifdef PCACHE_MONITOR
+       if ( rc == LDAP_SUCCESS ) {
+               rc = pcache_monitor_db_close( be );
+       }
+#endif /* PCACHE_MONITOR */
+
+       return rc;
+}
+
+static int
+pcache_db_destroy(
+       BackendDB *be,
+       ConfigReply *cr
+)
+{
+       slap_overinst *on = (slap_overinst *)be->bd_info;
+       cache_manager *cm = on->on_bi.bi_private;
+       query_manager *qm = cm->qm;
+       QueryTemplate *tm;
+       int i;
+
+       if ( cm->db.be_private != NULL ) {
+               backend_stopdown_one( &cm->db );
+       }
+
        while ( (tm = qm->templates) != NULL ) {
                CachedQuery *qc, *qn;
                qm->templates = tm->qmnext;
@@ -4902,29 +4928,6 @@ pcache_db_close(
        free( qm->attr_sets );
        qm->attr_sets = NULL;
 
-#ifdef PCACHE_MONITOR
-       if ( rc == LDAP_SUCCESS ) {
-               rc = pcache_monitor_db_close( be );
-       }
-#endif /* PCACHE_MONITOR */
-
-       return rc;
-}
-
-static int
-pcache_db_destroy(
-       BackendDB *be,
-       ConfigReply *cr
-)
-{
-       slap_overinst *on = (slap_overinst *)be->bd_info;
-       cache_manager *cm = on->on_bi.bi_private;
-       query_manager *qm = cm->qm;
-
-       if ( cm->db.be_private != NULL ) {
-               backend_stopdown_one( &cm->db );
-       }
-
        ldap_pvt_thread_mutex_destroy( &qm->lru_mutex );
        ldap_pvt_thread_mutex_destroy( &cm->cache_mutex );
        free( qm );
index b38e62a2fd57ed8fbdefd3a7bae31481229bd35a..f0a371902287efe1538bda3186bb77d0d171f709 100644 (file)
@@ -314,8 +314,21 @@ refint_db_destroy(
 
        if ( on->on_bi.bi_private ) {
                refint_data *id = on->on_bi.bi_private;
+               refint_attrs *ii, *ij;
+
                on->on_bi.bi_private = NULL;
                ldap_pvt_thread_mutex_destroy( &id->qmutex );
+
+               for(ii = id->attrs; ii; ii = ij) {
+                       ij = ii->next;
+                       ch_free(ii);
+               }
+
+               ch_free( id->nothing.bv_val );
+               BER_BVZERO( &id->nothing );
+               ch_free( id->nnothing.bv_val );
+               BER_BVZERO( &id->nnothing );
+
                ch_free( id );
        }
        return(0);
@@ -349,11 +362,8 @@ refint_open(
 
 
 /*
-** foreach configured attribute:
-**     free it;
 ** free our basedn;
-** reset on_bi.bi_private;
-** free our config data;
+** free our refintdn
 **
 */
 
@@ -365,20 +375,9 @@ refint_close(
 {
        slap_overinst *on       = (slap_overinst *) be->bd_info;
        refint_data *id = on->on_bi.bi_private;
-       refint_attrs *ii, *ij;
-
-       for(ii = id->attrs; ii; ii = ij) {
-               ij = ii->next;
-               ch_free(ii);
-       }
-       id->attrs = NULL;
 
        ch_free( id->dn.bv_val );
        BER_BVZERO( &id->dn );
-       ch_free( id->nothing.bv_val );
-       BER_BVZERO( &id->nothing );
-       ch_free( id->nnothing.bv_val );
-       BER_BVZERO( &id->nnothing );
        ch_free( id->refint_dn.bv_val );
        BER_BVZERO( &id->refint_dn );
        ch_free( id->refint_ndn.bv_val );
index 1a2506223ca7b3ee9e939b5d4df78ad31e4088ae..60d5f8338679abe51f9698f65cbd86345a497438 100644 (file)
@@ -168,6 +168,7 @@ seqmod_db_close(
                ldap_pvt_thread_mutex_destroy( &sm->sm_mutex );
 
                ch_free( sm );
+               on->on_bi.bi_private = NULL;
        }
 
        return 0;
index 856016226aaf1b9f32d8a9d9646f559dc6215b89..2015d8da2a17d4d5d0af73edd85e6695de9ebdc7 100644 (file)
@@ -149,4 +149,10 @@ servers to be cached locally. In both cases the overlays must provide a bit of
 glue to swap in the appropriate be_private and bd_info pointers before invoking
 the attached backend, which can then be invoked as usual.
 
+Note on overlay initialization/destruction: you should allocate storage for
+config info in the _db_init handler, and free this storage in the _db_destroy
+handler. You must not free it in the _db_close handler because a module may
+be opened/closed multiple times in a running slapd when using dynamic
+configuration and the config info must remain intact.
+
 ---
index 7b084af26a9c6c9d6139f7b29358f392fcbe859a..218771f118b0fcfb69e70112e30a130aaa130fb9 100644 (file)
@@ -823,47 +823,6 @@ unique_db_destroy(
        return 0;
 }
 
-static int
-unique_open(
-       BackendDB *be,
-       ConfigReply *cr
-)
-{
-       Debug(LDAP_DEBUG_TRACE, "unique_open: overlay initialized\n", 0, 0, 0);
-
-       return 0;
-}
-
-
-/*
-** Leave unique_data but wipe out config
-**
-*/
-
-static int
-unique_close(
-       BackendDB *be,
-       ConfigReply *cr
-)
-{
-       slap_overinst *on       = (slap_overinst *) be->bd_info;
-       unique_data **privatep = (unique_data **) &on->on_bi.bi_private;
-       unique_data *private = *privatep;
-
-       Debug(LDAP_DEBUG_TRACE, "==> unique_close\n", 0, 0, 0);
-
-       if ( private ) {
-               unique_domain *domains = private->domains;
-               unique_domain *legacy = private->legacy;
-
-               unique_free_domain ( domains );
-               unique_free_domain ( legacy );
-               memset ( private, 0, sizeof ( unique_data ) );
-       }
-
-       return ( 0 );
-}
-
 
 /*
 ** search callback
@@ -1465,8 +1424,6 @@ unique_initialize()
        unique.on_bi.bi_type = "unique";
        unique.on_bi.bi_db_init = unique_db_init;
        unique.on_bi.bi_db_destroy = unique_db_destroy;
-       unique.on_bi.bi_db_open = unique_open;
-       unique.on_bi.bi_db_close = unique_close;
        unique.on_bi.bi_op_add = unique_add;
        unique.on_bi.bi_op_modify = unique_modify;
        unique.on_bi.bi_op_modrdn = unique_modrdn;