Commit 651155d2 authored by Howard Chu's avatar Howard Chu
Browse files

ITS#4805 memleak fixes from HEAD

parent 9a965d8a
......@@ -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 )
{
......
......@@ -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.
*/
......
......@@ -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)
......
......@@ -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;
......
......@@ -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 );
......
......@@ -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();
......
......@@ -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 );
......
......@@ -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 &&
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment