]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/back-bdb/init.c
Plug memory leak
[openldap] / servers / slapd / back-bdb / init.c
index aa956d2b1e31049f10393a310913e3af98829cef..347e82bd2310c413964c0119a2e36321aced7eb9 100644 (file)
@@ -37,13 +37,13 @@ struct berval bdb_uuid = { 0, NULL };
 typedef void * db_malloc(size_t);
 typedef void * db_realloc(void *, size_t);
 
+#if 0
 static int
 bdb_open( BackendInfo *bi )
 {
        return 0;
 }
 
-#if 0
 static int
 bdb_destroy( BackendInfo *bi )
 {
@@ -92,6 +92,8 @@ bdb_db_init( BackendDB *be )
        bdb->bi_cache.c_maxsize = DEFAULT_CACHE_SIZE;
 
        bdb->bi_lock_detect = DB_LOCK_DEFAULT;
+       bdb->bi_search_stack_depth = DEFAULT_SEARCH_STACK_DEPTH;
+       bdb->bi_search_stack = NULL;
 
 #ifdef LDAP_CLIENT_UPDATE
        LDAP_LIST_INIT (&bdb->psearch_list);
@@ -106,6 +108,7 @@ bdb_db_init( BackendDB *be )
 #endif
 
        be->be_private = bdb;
+
        return 0;
 }
 
@@ -117,7 +120,7 @@ bdb_bt_compare(
 )
 {
        unsigned char *u, *c;
-       int i;
+       int i, x;
 
        u = usrkey->data;
        c = curkey->data;
@@ -128,9 +131,10 @@ bdb_bt_compare(
        for( i = sizeof(ID)-1; i >= 0; i--)
 #endif
        {
-               if( u[i] - c[i] )
-                       return u[i] - c[i];
+               x = u[i] - c[i];
+               if( x ) return x;
        }
+
        return 0;
 }
 
@@ -184,6 +188,13 @@ bdb_db_open( BackendDB *be )
        bdb->bi_dbenv->set_errcall( bdb->bi_dbenv, bdb_errcall );
        bdb->bi_dbenv->set_lk_detect( bdb->bi_dbenv, bdb->bi_lock_detect );
 
+#ifdef SLAP_IDL_CACHE
+       if ( bdb->bi_idl_cache_max_size ) {
+               ldap_pvt_thread_mutex_init( &bdb->bi_idl_tree_mutex );
+               bdb->bi_idl_cache_size = 0;
+       }
+#endif
+
 #ifdef BDB_SUBDIRS
        {
                char dir[MAXPATHLEN];
@@ -402,6 +413,9 @@ bdb_db_close( BackendDB *be )
        int rc;
        struct bdb_info *bdb = (struct bdb_info *) be->be_private;
        struct bdb_db_info *db;
+#ifdef SLAP_IDL_CACHE
+       bdb_idl_cache_entry_t *entry, *next_entry;
+#endif
 
        while( bdb->bi_ndatabases-- ) {
                db = bdb->bi_databases[bdb->bi_ndatabases];
@@ -416,6 +430,19 @@ bdb_db_close( BackendDB *be )
 
        bdb_cache_release_all (&bdb->bi_cache);
 
+#ifdef SLAP_IDL_CACHE
+       ldap_pvt_thread_mutex_lock ( &bdb->bi_idl_tree_mutex );
+       entry = bdb->bi_idl_lru_head;
+       while ( entry != NULL ) {
+               next_entry = entry->idl_lru_next;
+               free( entry->idl );
+               free( entry->kstr.bv_val );
+               free( entry );
+               entry = next_entry;
+       }
+       ldap_pvt_thread_mutex_unlock ( &bdb->bi_idl_tree_mutex );
+#endif
+
        return 0;
 }
 
@@ -495,14 +522,11 @@ bdb_initialize(
 {
        static char *controls[] = {
                LDAP_CONTROL_MANAGEDSAIT,
-#ifdef LDAP_CONTROL_SUBENTRIES
-               LDAP_CONTROL_SUBENTRIES,
-#endif
-#ifdef LDAP_CONTROL_NOOP
                LDAP_CONTROL_NOOP,
-#endif
-#ifdef LDAP_CONTROL_VALUESRETURNFILTER
+               LDAP_CONTROL_PAGEDRESULTS,
                LDAP_CONTROL_VALUESRETURNFILTER,
+#ifdef LDAP_CONTROL_SUBENTRIES
+               LDAP_CONTROL_SUBENTRIES,
 #endif
 #ifdef LDAP_CLIENT_UPDATE
                LDAP_CONTROL_CLIENT_UPDATE,
@@ -516,7 +540,7 @@ bdb_initialize(
 #ifdef NEW_LOGGING
        LDAP_LOG( BACK_BDB, ENTRY, "bdb_db_initialize\n", 0, 0, 0 );
 #else
-       Debug( LDAP_DEBUG_TRACE, "bdb_open: initialize BDB backend\n",
+       Debug( LDAP_DEBUG_TRACE, "bdb_initialize: initialize BDB backend\n",
                0, 0, 0 );
 #endif
 
@@ -545,7 +569,7 @@ bdb_initialize(
                                "\texpected: %s \tgot: %s\n", DB_VERSION_STRING, version, 0 );
 #else
                        Debug( LDAP_DEBUG_ANY,
-                               "bdb_open: version mismatch\n"
+                               "bdb_initialize: version mismatch\n"
                                "\texpected: " DB_VERSION_STRING "\n"
                                "\tgot: %s \n", version, 0, 0 );
 #endif
@@ -553,9 +577,9 @@ bdb_initialize(
 
 #ifdef NEW_LOGGING
                LDAP_LOG( BACK_BDB, DETAIL1, 
-                       "bdb_db_initialize: bdb_open: %s\n", version, 0, 0 );
+                       "bdb_db_initialize: %s\n", version, 0, 0 );
 #else
-               Debug( LDAP_DEBUG_ANY, "bdb_open: %s\n",
+               Debug( LDAP_DEBUG_ANY, "bdb_initialize: %s\n",
                        version, 0, 0 );
 #endif
        }
@@ -615,9 +639,7 @@ bdb_initialize(
 
        bi->bi_chk_referrals = bdb_referrals;
        bi->bi_operational = bdb_operational;
-#ifdef SLAP_X_FILTER_HASSUBORDINATES
        bi->bi_has_subordinates = bdb_hasSubordinates;
-#endif /* SLAP_X_FILTER_HASSUBORDINATES */
        bi->bi_entry_release_rw = bdb_entry_release;
 
        /*