]> git.sur5r.net Git - openldap/commitdiff
Plug more memleaks
authorHoward Chu <hyc@openldap.org>
Thu, 21 Jul 2005 23:26:40 +0000 (23:26 +0000)
committerHoward Chu <hyc@openldap.org>
Thu, 21 Jul 2005 23:26:40 +0000 (23:26 +0000)
servers/slapd/back-bdb/alock.c
servers/slapd/back-ldif/ldif.c
servers/slapd/backend.c
servers/slapd/bconfig.c
servers/slapd/proto-slap.h
servers/slapd/value.c

index 4951e8ffabc947d3dda6a4c21cd56e1c0a973129..1410413e9e34c689dcd7f3302ee7ee16cf35faa8 100644 (file)
@@ -295,11 +295,12 @@ alock_query_slot ( alock_info_t * info )
        
        (void) memset ((void *) &slot_data, 0, sizeof (alock_slot_t));
        alock_read_slot (info, &slot_data);
-       if (slot_data.al_lock == ALOCK_UNLOCKED) return ALOCK_UNLOCKED;
 
        if (slot_data.al_appname != NULL) free (slot_data.al_appname);
        slot_data.al_appname = NULL;
 
+       if (slot_data.al_lock == ALOCK_UNLOCKED) return ALOCK_UNLOCKED;
+
        res = alock_test_lock (info->al_fd, info->al_slot);
        if (res < 0) return -1;
        if (res > 0) {
index fa5ee9b0315d65d66165cd6bfe52ff5b732cfac2..9e9145d6481ae318b7adcc3a066d7af3ffcbc49d 100644 (file)
@@ -1164,6 +1164,8 @@ ldif_back_db_destroy(
                           )
 {
        struct ldif_info *ni = be->be_private;
+
+       ch_free(ni->li_base_path.bv_val);
        ldap_pvt_thread_mutex_destroy(&ni->li_mutex);
        free( be->be_private );
        return 0;
index a2e476ded12a7512add9d08d93e56b54874cac4e..3840ea02e914d8d2001dca1a3ae1f14b973f3651 100644 (file)
@@ -382,9 +382,11 @@ int backend_shutdown( Backend *be )
        return 0;
 }
 
-void backend_destroy_one( BackendDB *bd )
+void backend_destroy_one( BackendDB *bd, int dynamic )
 {
-       LDAP_STAILQ_REMOVE(&backendDB, bd, slap_backend_db, be_next );
+       if ( dynamic ) {
+               LDAP_STAILQ_REMOVE(&backendDB, bd, slap_backend_db, be_next );
+       }
 
        if ( bd->be_syncinfo ) {
                syncinfo_free( bd->be_syncinfo );
@@ -401,6 +403,7 @@ void backend_destroy_one( BackendDB *bd )
                        csne = LDAP_TAILQ_NEXT( csne, ce_csn_link );
                        ch_free( tmp_csne );
                }
+               ch_free( bd->be_pending_csn_list );
        }
 
        if ( bd->bd_info->bi_db_destroy ) {
@@ -418,7 +421,9 @@ void backend_destroy_one( BackendDB *bd )
                free( bd->be_rootpw.bv_val );
        }
        acl_destroy( bd->be_acl, frontendDB->be_acl );
-       free( bd );
+       if ( dynamic ) {
+               free( bd );
+       }
 }
 
 int backend_destroy(void)
@@ -428,7 +433,7 @@ int backend_destroy(void)
 
        /* destroy each backend database */
        while (( bd = LDAP_STAILQ_FIRST(&backendDB))) {
-               backend_destroy_one( bd );
+               backend_destroy_one( bd, 1 );
        }
 
        /* destroy each backend type */
index 430ef92831fcba17ee0c477bc108c5819bac59ec..1ba2f24c14be1d1ab3de8a7f2c2300205390bb83 100644 (file)
@@ -2541,6 +2541,8 @@ config_setup_ldif( BackendDB *be, const char *dir, int readit ) {
 
                op->o_bd = &cfb->cb_db;
                rc = op->o_bd->be_search( op, &rs );
+
+               slap_sl_mem_destroy( NULL, op->o_tmpmemctx );
        }
 
        cfb->cb_use_ldif = 1;
@@ -3218,7 +3220,7 @@ ok:
 leave:
        if ( rc ) {
                if ( (colst[0]->co_type == Cft_Database) && ca->be ) {
-                       backend_destroy_one( ca->be );
+                       backend_destroy_one( ca->be, 1 );
                } else if ( (colst[0]->co_type == Cft_Overlay) && ca->bi ) {
                        overlay_destroy_one( ca->be, (slap_overinst *)ca->bi );
                }
@@ -4005,6 +4007,8 @@ config_back_db_open( BackendDB *be )
                        }
                }
        }
+       if ( op )
+               slap_sl_mem_destroy( NULL, op->o_tmpmemctx );
 
        return 0;
 }
@@ -4044,21 +4048,30 @@ config_back_db_close( BackendDB *be )
 {
        CfBackInfo *cfb = be->be_private;
 
-       /* Note - this is asymmetric; cfb->cb_config was allocated in db_init
-        * not db_open. We cannot re-open this DB after a close. (Not that we
-        * ever could anyway.)
-        */
-       cfb_free_cffile( cfb->cb_config );
-       cfb->cb_config = NULL;
-
        cfb_free_entries( cfb->cb_root );
        cfb->cb_root = NULL;
+
+       backend_shutdown( &cfb->cb_db );
        return 0;
 }
 
 static int
 config_back_db_destroy( BackendDB *be )
 {
+       CfBackInfo *cfb = be->be_private;
+
+       cfb_free_cffile( cfb->cb_config );
+
+       ch_free( cfdir.bv_val );
+
+       avl_free( CfOcTree, NULL );
+
+       cfb->cb_db.be_suffix = NULL;
+       cfb->cb_db.be_nsuffix = NULL;
+       cfb->cb_db.be_rootdn.bv_val = NULL;
+       cfb->cb_db.be_rootndn.bv_val = NULL;
+       backend_destroy_one( &cfb->cb_db, 0 );
+
        free( be->be_private );
        return 0;
 }
index b571762887ba6403a50d63bdc42681b960a89827..39b4cef11341df996f47d7fad199c8a17c49131a 100644 (file)
@@ -264,7 +264,7 @@ LDAP_SLAPD_F (int) backend_startup_one LDAP_P((Backend *be));
 LDAP_SLAPD_F (int) backend_sync LDAP_P((Backend *be));
 LDAP_SLAPD_F (int) backend_shutdown LDAP_P((Backend *be));
 LDAP_SLAPD_F (int) backend_destroy LDAP_P((void));
-LDAP_SLAPD_F (void) backend_destroy_one LDAP_P((BackendDB *bd));
+LDAP_SLAPD_F (void) backend_destroy_one LDAP_P((BackendDB *bd, int dynamic));
 
 LDAP_SLAPD_F (BackendInfo *) backend_info LDAP_P(( const char *type ));
 LDAP_SLAPD_F (BackendDB *) backend_db_init LDAP_P(( const char *type ));
index 174a30579d2ffc2e464890bcf5187ad132d3b0cf..aab6b34bc85fb6ae347efc0d2fcce92c70332347 100644 (file)
@@ -385,6 +385,7 @@ ordered_value_sort( Attribute *a, int do_renumber )
                if ( indexes[0] != 0 || indexes[vals-1] != vals-1 ) {
                        renumber = 1;
                }
+               ch_free( indexes );
        } else {
                renumber = 1;
        }