]> git.ipfire.org Git - thirdparty/openldap.git/commitdiff
ITS#4805 memleak fixes from HEAD
authorHoward Chu <hyc@openldap.org>
Thu, 25 Jan 2007 13:42:38 +0000 (13:42 +0000)
committerHoward Chu <hyc@openldap.org>
Thu, 25 Jan 2007 13:42:38 +0000 (13:42 +0000)
servers/slapd/back-bdb/cache.c
servers/slapd/back-bdb/init.c
servers/slapd/back-bdb/proto-bdb.h
servers/slapd/back-monitor/init.c
servers/slapd/connection.c
servers/slapd/init.c
servers/slapd/main.c
servers/slapd/sasl.c

index ed34a2314877573cb341d115b0fd58e15afdc1ee..3daba0b7c29074e5912c8c4a52a55f032c7132d6 100644 (file)
@@ -1293,6 +1293,19 @@ bdb_locker_id_free( void *key, void *data )
        }
 }
 
+/* free up any keys used by the main thread */
+void
+bdb_locker_flush( DB_ENV *env )
+{
+       void *data;
+       void *ctx = ldap_pvt_thread_pool_context();
+
+       if ( !ldap_pvt_thread_pool_getkey( ctx, env, &data, NULL ) ) {
+               ldap_pvt_thread_pool_setkey( ctx, env, NULL, NULL );
+               bdb_locker_id_free( env, data );
+       }
+}
+
 int
 bdb_locker_id( Operation *op, DB_ENV *env, u_int32_t *locker )
 {
index 8ffc121a12b47d1c24abc509254575d2ae253795..cc7193c73044ec3a1da5a1d04d99d8f08c9391b3 100644 (file)
@@ -481,7 +481,9 @@ bdb_db_close( BackendDB *be )
                        XLOCK_ID_FREE(bdb->bi_dbenv, bdb->bi_cache.c_locker);
                        bdb->bi_cache.c_locker = 0;
                }
-
+#ifdef BDB_REUSE_LOCKERS
+               bdb_locker_flush( bdb->bi_dbenv );
+#endif
                /* force a checkpoint, but not if we were ReadOnly,
                 * and not in Quick mode since there are no transactions there.
                 */
index 1a8d71a5d9d08f7d6de91827c001e61cc6698bc6..85fb1766c4d1b583550a91e47c4c33b7be0e3a51 100644 (file)
@@ -574,7 +574,9 @@ int bdb_cache_entry_db_unlock(
 #ifdef BDB_REUSE_LOCKERS
 
 #define bdb_locker_id                          BDB_SYMBOL(locker_id)
+#define bdb_locker_flush                       BDB_SYMBOL(locker_flush)
 int bdb_locker_id( Operation *op, DB_ENV *env, u_int32_t *locker );
+void bdb_locker_flush( DB_ENV *env );
 
 #define        LOCK_ID_FREE(env, locker)       ((void)0)
 #define        LOCK_ID(env, locker)    bdb_locker_id(op, env, locker)
index f093e693bb3fa31e8394c9f242ac5a516a6910c4..4bade2a201120a5754f1aa6b65b459ddc8dea2ec 100644 (file)
@@ -644,6 +644,7 @@ monitor_filter2ndn(
        Connection      conn = { 0 };
        OperationBuffer opbuf;
        Operation       *op;
+       void    *thrctx;
        SlapReply       rs = { 0 };
        slap_callback   cb = { NULL, monitor_filter2ndn_cb, NULL, NULL };
        int             rc;
@@ -655,18 +656,11 @@ monitor_filter2ndn(
        }
 
        op = (Operation *) &opbuf;
-       connection_fake_init( &conn, op, &conn );
+       thrctx = ldap_pvt_thread_pool_context();
+       connection_fake_init( &conn, op, thrctx );
 
        op->o_tag = LDAP_REQ_SEARCH;
 
-       /* use global malloc for now */
-       if ( op->o_tmpmemctx ) {
-               /* FIXME: connection_fake_init() calls slap_sl_mem_create, so we destroy it for now */
-               slap_sl_mem_destroy( NULL, op->o_tmpmemctx );
-               op->o_tmpmemctx = NULL;
-       }
-       op->o_tmpmfuncs = &ch_mfuncs;
-
        op->o_bd = be_monitor;
        if ( base == NULL || BER_BVISNULL( base ) ) {
                ber_dupbv_x( &op->o_req_dn, &op->o_bd->be_suffix[ 0 ],
@@ -704,8 +698,8 @@ monitor_filter2ndn(
 
        filter_free_x( op, op->ors_filter );
        op->o_tmpfree( op->ors_filterstr.bv_val, op->o_tmpmemctx );
-       op->o_tmpfree( op->o_req_dn.bv_val, op->o_tmpmemctx );
        op->o_tmpfree( op->o_req_ndn.bv_val, op->o_tmpmemctx );
+       op->o_tmpfree( op->o_req_dn.bv_val, op->o_tmpmemctx );
 
        if ( rc != 0 ) {
                return rc;
index 10a90ee93f7f77c7b7029a203a398127179bfc1b..99d8edbbdccd5ad24c0e4c1659ff0f54beec3cce 100644 (file)
@@ -1950,6 +1950,38 @@ int connection_write(ber_socket_t s)
        return 0;
 }
 
+#ifdef LDAP_SLAPI
+typedef struct conn_fake_extblock {
+       void *eb_conn;
+       void *eb_op;
+} conn_fake_extblock;
+
+static void
+connection_fake_destroy(
+       void *key,
+       void *data )
+{
+       Connection conn = {0};
+       Operation op = {0};
+       Opheader ohdr = {0};
+
+       conn_fake_extblock *eb = data;
+       
+       op.o_hdr = &ohdr;
+       op.o_hdr->oh_extensions = eb->eb_op;
+       conn.c_extensions = eb->eb_conn;
+       op.o_conn = &conn;
+       conn.c_connid = -1;
+       op.o_connid = -1;
+
+       Debug(LDAP_DEBUG_ANY, "connection_fake_destroy: %p\n", eb, 0, 0 );
+
+       ber_memfree_x( eb, NULL );
+       slapi_int_free_object_extensions( SLAPI_X_EXT_OPERATION, &op );
+       slapi_int_free_object_extensions( SLAPI_X_EXT_CONNECTION, &conn );
+}
+#endif
+
 void
 connection_fake_init(
        Connection *conn,
@@ -1980,8 +2012,25 @@ connection_fake_init(
        connection_init_log_prefix( op );
 
 #ifdef LDAP_SLAPI
-       slapi_int_create_object_extensions( SLAPI_X_EXT_CONNECTION, conn );
-       slapi_int_create_object_extensions( SLAPI_X_EXT_OPERATION, op );
+       if ( slapi_plugins_used ) {
+               conn_fake_extblock *eb = NULL;
+
+               /* Use thread keys to make sure these eventually get cleaned up */
+               if ( ldap_pvt_thread_pool_getkey( ctx, connection_fake_init, &eb,
+                       NULL )) {
+                       eb = ch_malloc( sizeof( *eb ));
+                       Debug(LDAP_DEBUG_ANY, "connection_fake_init: ctx %p, %p\n", ctx, eb, 0 );
+                       slapi_int_create_object_extensions( SLAPI_X_EXT_CONNECTION, conn );
+                       slapi_int_create_object_extensions( SLAPI_X_EXT_OPERATION, op );
+                       eb->eb_conn = conn->c_extensions;
+                       eb->eb_op = op->o_hdr->oh_extensions;
+                       ldap_pvt_thread_pool_setkey( ctx, connection_fake_init, eb,
+                               connection_fake_destroy );
+               } else {
+                       conn->c_extensions = eb->eb_conn;
+                       op->o_hdr->oh_extensions = eb->eb_op;
+               }
+       }
 #endif /* LDAP_SLAPI */
 
        slap_op_time( &op->o_time, &op->o_tincr );
index 9c3cca1c183113b7786e3b748bc3d5f6dfd8c772..9a048b64eb5417f0a0095d7569cee92ae1b55962 100644 (file)
@@ -300,6 +300,9 @@ int slap_destroy(void)
                ber_bvarray_free( default_referral );
        }
 
+       /* clear out any thread-keys for the main thread */
+       ldap_pvt_thread_pool_context_reset( ldap_pvt_thread_pool_context());
+
        rc = backend_destroy();
 
        slap_sasl_destroy();
index d4c87dfc61768f23dadba4f82062cd4891373b55..7cff762abe425eb80e8f380ec7812b8d5095105a 100644 (file)
@@ -753,6 +753,12 @@ unhandled_option:;
        }
 #endif
 
+#ifdef HAVE_CYRUS_SASL
+       if( global_host == NULL ) {
+               global_host = ldap_pvt_get_fqdn( NULL );
+       }
+#endif
+
        (void) SIGNAL( LDAP_SIGUSR1, slap_sig_wake );
        (void) SIGNAL( LDAP_SIGUSR2, slap_sig_shutdown );
 
index 5863ca2e231162adc9b7a8fbdde95dbf1d86ac1d..9a761e828484d2fed2a0c78d60470b92e94a7ecb 100644 (file)
@@ -1103,10 +1103,6 @@ int slap_sasl_open( Connection *conn, int reopen )
 
        conn->c_sasl_layers = 0;
 
-       if( global_host == NULL ) {
-               global_host = ldap_pvt_get_fqdn( NULL );
-       }
-
        /* create new SASL context */
 #if SASL_VERSION_MAJOR >= 2
        if ( conn->c_sock_name.bv_len != 0 &&