From: Howard Chu Date: Thu, 25 Jan 2007 13:42:38 +0000 (+0000) Subject: ITS#4805 memleak fixes from HEAD X-Git-Tag: OPENLDAP_REL_ENG_2_3_34~18 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=651155d248869ad0a9e98803b6f44b873c56affb;p=thirdparty%2Fopenldap.git ITS#4805 memleak fixes from HEAD --- diff --git a/servers/slapd/back-bdb/cache.c b/servers/slapd/back-bdb/cache.c index ed34a23148..3daba0b7c2 100644 --- a/servers/slapd/back-bdb/cache.c +++ b/servers/slapd/back-bdb/cache.c @@ -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 ) { diff --git a/servers/slapd/back-bdb/init.c b/servers/slapd/back-bdb/init.c index 8ffc121a12..cc7193c730 100644 --- a/servers/slapd/back-bdb/init.c +++ b/servers/slapd/back-bdb/init.c @@ -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. */ diff --git a/servers/slapd/back-bdb/proto-bdb.h b/servers/slapd/back-bdb/proto-bdb.h index 1a8d71a5d9..85fb1766c4 100644 --- a/servers/slapd/back-bdb/proto-bdb.h +++ b/servers/slapd/back-bdb/proto-bdb.h @@ -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) diff --git a/servers/slapd/back-monitor/init.c b/servers/slapd/back-monitor/init.c index f093e693bb..4bade2a201 100644 --- a/servers/slapd/back-monitor/init.c +++ b/servers/slapd/back-monitor/init.c @@ -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; diff --git a/servers/slapd/connection.c b/servers/slapd/connection.c index 10a90ee93f..99d8edbbdc 100644 --- a/servers/slapd/connection.c +++ b/servers/slapd/connection.c @@ -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 ); diff --git a/servers/slapd/init.c b/servers/slapd/init.c index 9c3cca1c18..9a048b64eb 100644 --- a/servers/slapd/init.c +++ b/servers/slapd/init.c @@ -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(); diff --git a/servers/slapd/main.c b/servers/slapd/main.c index d4c87dfc61..7cff762abe 100644 --- a/servers/slapd/main.c +++ b/servers/slapd/main.c @@ -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 ); diff --git a/servers/slapd/sasl.c b/servers/slapd/sasl.c index 5863ca2e23..9a761e8284 100644 --- a/servers/slapd/sasl.c +++ b/servers/slapd/sasl.c @@ -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 &&