]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/overlays/sssvlv.c
ITS#6649
[openldap] / servers / slapd / overlays / sssvlv.c
index 7dc3dab8e218761b9d5ca7e48267ec56aaff692b..10a0d00cb7dc3a2298ce00938baf11055a1b61f1 100644 (file)
@@ -113,6 +113,7 @@ typedef struct sort_op
 /* There is only one conn table for all overlay instances */
 static sort_op **sort_conns;
 static ldap_pvt_thread_mutex_t sort_conns_mutex;
+static int ov_count;
 static const char *debug_header = "sssvlv";
 
 static int sss_cid;
@@ -470,7 +471,9 @@ range_err:
        be = op->o_bd;
        for ( i=0; i<j; i++ ) {
                sort_node *sn = cur_node->avl_data;
-               
+
+               if ( slapd_shutdown ) break;
+
                op->o_bd = select_backend( &sn->sn_dn, 0 );
                e = NULL;
                rc = be_entry_get_rw( op, &sn->sn_dn, NULL, NULL, 0, &e );
@@ -502,6 +505,8 @@ static void send_page( Operation *op, SlapReply *rs, sort_op *so )
        while ( cur_node && rs->sr_nentries < so->so_page_size ) {
                sort_node *sn = cur_node->avl_data;
 
+               if ( slapd_shutdown ) break;
+
                next_node = tavl_next( cur_node, TAVL_DIR_RIGHT );
 
                op->o_bd = select_backend( &sn->sn_dn, 0 );
@@ -796,9 +801,9 @@ static int sssvlv_op_search(
                                op->o_tmpmemctx );
                        /* Install serversort response callback to handle a new search */
                        if ( ps || vc ) {
-                               so = ch_malloc( sizeof(sort_op));
+                               so = ch_calloc( 1, sizeof(sort_op));
                        } else {
-                               so = op->o_tmpalloc( sizeof(sort_op), op->o_tmpmemctx );
+                               so = op->o_tmpcalloc( 1, sizeof(sort_op), op->o_tmpmemctx );
                        }
                        sort_conns[op->o_conn->c_conn_idx] = so;
 
@@ -821,6 +826,8 @@ static int sssvlv_op_search(
                                        so->so_vlv = op->o_ctrlflag[vlv_cid];
                                        so->so_vlv_target = 0;
                                        so->so_vlv_rc = 0;
+                               } else {
+                                       so->so_vlv = SLAP_CONTROL_NONE;
                                }
                        }
                        so->so_vcontext = (unsigned long)so;
@@ -1165,6 +1172,7 @@ static int sssvlv_db_init(
                sort_conns = ch_calloc( sizeof(sort_op *), dtblsize + 1 );
                sort_conns++;
        }
+       ov_count++;
 
        return LDAP_SUCCESS;
 }
@@ -1176,6 +1184,13 @@ static int sssvlv_db_destroy(
        slap_overinst   *on = (slap_overinst *)be->bd_info;
        sssvlv_info *si = (sssvlv_info *)on->on_bi.bi_private;
        
+       ov_count--;
+       if ( !ov_count && sort_conns) {
+               sort_conns--;
+               ch_free(sort_conns);
+               ldap_pvt_thread_mutex_destroy( &sort_conns_mutex );
+       }
+       
        if ( si ) {
                ch_free( si );
                on->on_bi.bi_private = NULL;
@@ -1221,11 +1236,11 @@ int sssvlv_initialize()
        if ( rc == LDAP_SUCCESS ) {
                rc = overlay_register( &sssvlv );
                if ( rc != LDAP_SUCCESS ) {
-                       fprintf( stderr, "Failed to register server side sort overlay\n" );
+                       Debug( LDAP_DEBUG_ANY, "Failed to register server side sort overlay\n", 0, 0, 0 );
                }
        }
        else {
-               fprintf( stderr, "Failed to register control %d\n", rc );
+               Debug( LDAP_DEBUG_ANY, "Failed to register control %d\n", rc, 0, 0 );
        }
 
        return rc;