]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/overlays/pcache.c
ITS#7906,#7923 Don't free configinfo in _db_close
[openldap] / servers / slapd / overlays / pcache.c
index 1fa8d1ede429d10ce96fb3f1faf6c5f0ab386083..291dddf0f23bded80b13fbe34b41dab5875cc0ca 100644 (file)
@@ -1,7 +1,7 @@
 /* $OpenLDAP$ */
 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
  *
- * Copyright 2003-2013 The OpenLDAP Foundation.
+ * Copyright 2003-2014 The OpenLDAP Foundation.
  * Portions Copyright 2003 IBM Corporation.
  * Portions Copyright 2003-2009 Symas Corporation.
  * All rights reserved.
@@ -37,7 +37,6 @@
 
 #include "config.h"
 
-#ifdef LDAP_DEVEL
 /*
  * Control that allows to access the private DB
  * instead of the public one
@@ -53,7 +52,6 @@
  * Monitoring
  */
 #define PCACHE_MONITOR
-#endif
 
 /* query cache structs */
 /* query */
@@ -2794,17 +2792,16 @@ pcache_op_privdb(
        /* map tag to operation */
        type = slap_req2op( op->o_tag );
        if ( type != SLAP_OP_LAST ) {
-               BI_op_func      **func;
+               BackendInfo     *bi = cm->db.bd_info;
                int             rc;
 
                /* execute, if possible */
-               func = &cm->db.be_bind;
-               if ( func[ type ] != NULL ) {
+               if ( (&bi->bi_op_bind)[ type ] ) {
                        Operation       op2 = *op;
        
                        op2.o_bd = &cm->db;
 
-                       rc = func[ type ]( &op2, rs );
+                       rc = (&bi->bi_op_bind)[ type ]( &op2, rs );
                        if ( type == SLAP_OP_BIND && rc == LDAP_SUCCESS ) {
                                op->o_conn->c_authz_cookie = cm->db.be_private;
                        }
@@ -4497,6 +4494,7 @@ pcache_db_init(
        qm = (query_manager*)ch_malloc(sizeof(query_manager));
 
        cm->db = *be;
+       cm->db.bd_info = NULL;
        SLAP_DBFLAGS(&cm->db) |= SLAP_DBFLAG_NO_SCHEMA_CHECK;
        cm->db.be_private = NULL;
        cm->db.bd_self = &cm->db;
@@ -4782,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 ) {
@@ -4792,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 ) {
@@ -4863,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;
@@ -4904,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 );