Commit 130f6e1b authored by Howard Chu's avatar Howard Chu
Browse files

Memory context tweaks for other ops

parent 784672d6
......@@ -78,7 +78,7 @@ do_add( Operation *op, SlapReply *rs )
e = (Entry *) ch_calloc( 1, sizeof(Entry) );
rs->sr_err = dnPrettyNormal( NULL, &dn, &e->e_name, &e->e_nname, op->o_tmpmemctx );
rs->sr_err = dnPrettyNormal( NULL, &dn, &op->o_req_dn, &op->o_req_ndn, op->o_tmpmemctx );
if( rs->sr_err != LDAP_SUCCESS ) {
#ifdef NEW_LOGGING
......@@ -91,6 +91,9 @@ do_add( Operation *op, SlapReply *rs )
goto done;
}
ber_dupbv( &e->e_name, &op->o_req_dn );
ber_dupbv( &e->e_nname, &op->o_req_ndn );
#ifdef NEW_LOGGING
LDAP_LOG( OPERATION, ARGS,
"do_add: conn %d dn (%s)\n", op->o_connid, e->e_dn, 0 );
......@@ -98,9 +101,6 @@ do_add( Operation *op, SlapReply *rs )
Debug( LDAP_DEBUG_ARGS, "do_add: dn (%s)\n", e->e_dn, 0, 0 );
#endif
op->o_req_dn = e->e_name;
op->o_req_ndn = e->e_nname;
/* get the attrs */
for ( tag = ber_first_element( ber, &len, &last ); tag != LBER_DEFAULT;
tag = ber_next_element( ber, &len, last ) )
......@@ -242,7 +242,7 @@ do_add( Operation *op, SlapReply *rs )
size_t textlen = sizeof textbuf;
rs->sr_err = slap_mods_check( modlist, update, &rs->sr_text,
textbuf, textlen, op->o_tmpmemctx );
textbuf, textlen, NULL );
if( rs->sr_err != LDAP_SUCCESS ) {
send_ldap_result( op, rs );
......@@ -353,6 +353,8 @@ done:
if( e != NULL ) {
entry_free( e );
}
op->o_tmpfree( op->o_req_dn.bv_val, op->o_tmpmemctx );
op->o_tmpfree( op->o_req_ndn.bv_val, op->o_tmpmemctx );
return rs->sr_err;
}
......
......@@ -156,8 +156,13 @@ bdb_cache_entry_db_lock
else
db_rw = DB_LOCK_READ;
#if 0
lockobj.data = e->e_nname.bv_val;
lockobj.size = e->e_nname.bv_len;
#else
lockobj.data = &e->e_private;
lockobj.size = sizeof(e->e_private);
#endif
rc = LOCK_GET(env, locker, flags | DB_LOCK_NOWAIT,
&lockobj, db_rw, lock);
if (rc) {
......
......@@ -647,7 +647,11 @@ retry: /* transaction retry */
/* Build target dn and make sure target entry doesn't exist already. */
if (!new_dn.bv_val) build_new_dn( &new_dn, new_parent_dn, &op->oq_modrdn.rs_newrdn );
if (!new_ndn.bv_val) dnNormalize2( NULL, &new_dn, &new_ndn, op->o_tmpmemctx );
if (!new_ndn.bv_val) {
struct berval bv = {0, NULL};
dnNormalize2( NULL, &new_dn, &bv, op->o_tmpmemctx );
ber_dupbv( &new_ndn, &bv );
}
#ifdef NEW_LOGGING
LDAP_LOG ( OPERATION, RESULTS,
......@@ -922,10 +926,10 @@ done:
/* LDAP v2 supporting correct attribute handling. */
if ( new_rdn != NULL ) {
ldap_rdnfree( new_rdn );
ldap_rdnfree_x( new_rdn, op->o_tmpmemctx );
}
if ( old_rdn != NULL ) {
ldap_rdnfree( old_rdn );
ldap_rdnfree_x( old_rdn, op->o_tmpmemctx );
}
if( mod != NULL ) {
Modifications *tmp;
......
......@@ -272,7 +272,7 @@ done:
}
if( ndn.bv_val != NULL ) {
free( ndn.bv_val );
op->o_tmpfree( ndn.bv_val, op->o_tmpmemctx );
}
if( ltid != NULL ) {
......
......@@ -466,7 +466,7 @@ ldbm_back_modrdn(
/* Build target dn and make sure target entry doesn't exist already. */
build_new_dn( &new_dn, new_parent_dn, &op->oq_modrdn.rs_newrdn );
dnNormalize2( NULL, &new_dn, &new_ndn, op->o_tmpmemctx );
dnNormalize2( NULL, &new_dn, &new_ndn, NULL );
#ifdef NEW_LOGGING
LDAP_LOG( BACK_LDBM, DETAIL1, "ldbm_back_modrdn: new ndn=%s\n",
......
......@@ -176,7 +176,7 @@ done:
}
if( ndn.bv_val != NULL ) {
free( ndn.bv_val );
op->o_tmpfree( ndn.bv_val, op->o_tmpmemctx );
}
return rc;
......
......@@ -299,9 +299,9 @@ do_compare(
#endif /* defined( LDAP_SLAPI ) */
cleanup:
free( op->o_req_dn.bv_val );
free( op->o_req_ndn.bv_val );
if ( ava.aa_value.bv_val ) free( ava.aa_value.bv_val );
op->o_tmpfree( op->o_req_dn.bv_val, op->o_tmpmemctx );
op->o_tmpfree( op->o_req_ndn.bv_val, op->o_tmpmemctx );
if ( ava.aa_value.bv_val ) op->o_tmpfree( ava.aa_value.bv_val, op->o_tmpmemctx );
return rs->sr_err;
}
......
......@@ -912,21 +912,21 @@ connection_operation( void *ctx, void *arg_v )
goto operations_error;
}
/* For all operations besides Add, we can use thread-local
* storage for most mallocs.
/* We can use Thread-Local storage for most mallocs. We can
* also use TL for ber parsing, but not on Add or Modify.
*/
#define SLAB_SIZE 1048576
memsiz = ber_len( op->o_ber ) * 32;
#if 0
memsiz = ber_len( op->o_ber ) * 64;
if ( SLAB_SIZE > memsiz ) memsiz = SLAB_SIZE;
#endif
memsiz = SLAB_SIZE;
if ( tag == LDAP_REQ_SEARCH || tag == LDAP_REQ_BIND ) {
memctx = sl_mem_create( memsiz, ctx );
memctx = sl_mem_create( memsiz, ctx );
op->o_tmpmemctx = memctx;
op->o_tmpmfuncs = &sl_mfuncs;
if ( tag != LDAP_REQ_ADD && tag != LDAP_REQ_MODIFY ) {
ber_set_option( op->o_ber, LBER_OPT_BER_MEMCTX, memctx );
op->o_tmpmemctx = memctx;
op->o_tmpmfuncs = &sl_mfuncs;
} else {
op->o_tmpmemctx = NULL;
op->o_tmpmfuncs = &ch_mfuncs;
}
switch ( tag ) {
......
......@@ -228,7 +228,7 @@ do_delete(
#endif /* defined( LDAP_SLAPI ) */
cleanup:
free( op->o_req_dn.bv_val );
free( op->o_req_ndn.bv_val );
op->o_tmpfree( op->o_req_dn.bv_val, op->o_tmpmemctx );
op->o_tmpfree( op->o_req_ndn.bv_val, op->o_tmpmemctx );
return rs->sr_err;
}
......@@ -394,7 +394,7 @@ do_modify(
size_t textlen = sizeof textbuf;
rs->sr_err = slap_mods_check( modlist, update, &rs->sr_text,
textbuf, textlen, op->o_tmpmemctx );
textbuf, textlen, NULL );
if( rs->sr_err != LDAP_SUCCESS ) {
send_ldap_result( op, rs );
......@@ -459,8 +459,8 @@ do_modify(
#endif /* defined( LDAP_SLAPI ) */
cleanup:
free( op->o_req_dn.bv_val );
free( op->o_req_ndn.bv_val );
op->o_tmpfree( op->o_req_dn.bv_val, op->o_tmpmemctx );
op->o_tmpfree( op->o_req_ndn.bv_val, op->o_tmpmemctx );
if ( modlist != NULL ) slap_mods_free( modlist );
#if defined( LDAP_SLAPI )
if ( modv != NULL ) slapi_x_free_ldapmods( modv );
......
......@@ -390,14 +390,14 @@ do_modrdn(
#endif /* defined( LDAP_SLAPI ) */
cleanup:
free( op->o_req_dn.bv_val );
free( op->o_req_ndn.bv_val );
op->o_tmpfree( op->o_req_dn.bv_val, op->o_tmpmemctx );
op->o_tmpfree( op->o_req_ndn.bv_val, op->o_tmpmemctx );
free( op->orr_newrdn.bv_val );
free( op->orr_nnewrdn.bv_val );
op->o_tmpfree( op->orr_newrdn.bv_val, op->o_tmpmemctx );
op->o_tmpfree( op->orr_nnewrdn.bv_val, op->o_tmpmemctx );
if ( pnewSuperior.bv_val ) free( pnewSuperior.bv_val );
if ( nnewSuperior.bv_val ) free( nnewSuperior.bv_val );
if ( pnewSuperior.bv_val ) op->o_tmpfree( pnewSuperior.bv_val, op->o_tmpmemctx );
if ( nnewSuperior.bv_val ) op->o_tmpfree( nnewSuperior.bv_val, op->o_tmpmemctx );
return rs->sr_err;
}
......
......@@ -238,7 +238,10 @@ send_ldap_response(
ber = op->o_res_ber;
else
#endif
ber_init_w_nullc( ber, LBER_USE_DER );
{
ber_init_w_nullc( ber, LBER_USE_DER );
ber_set_option( ber, LBER_OPT_BER_MEMCTX, op->o_tmpmemctx );
}
#ifdef NEW_LOGGING
LDAP_LOG( OPERATION, ENTRY,
......@@ -1189,8 +1192,9 @@ slap_send_search_reference( Operation *op, SlapReply *rs )
{
char berbuf[LBER_ELEMENT_SIZEOF];
BerElement *ber = (BerElement *)berbuf;
int rc;
int rc = 0;
int bytes;
void *mark;
AttributeDescription *ad_ref = slap_schema.si_ad_ref;
AttributeDescription *ad_entry = slap_schema.si_ad_entry;
......@@ -1200,6 +1204,8 @@ slap_send_search_reference( Operation *op, SlapReply *rs )
return op->o_callback->sc_response( op, rs );
}
mark = sl_mark( op->o_tmpmemctx );
#ifdef NEW_LOGGING
LDAP_LOG( OPERATION, ENTRY,
"send_search_reference: conn %lu dn=\"%s\"\n",
......@@ -1223,8 +1229,8 @@ slap_send_search_reference( Operation *op, SlapReply *rs )
"send_search_reference: access to entry not allowed\n",
0, 0, 0 );
#endif
return( 1 );
rc = 1;
goto rel;
}
if ( rs->sr_entry && ! access_allowed( op, rs->sr_entry,
......@@ -1240,8 +1246,8 @@ slap_send_search_reference( Operation *op, SlapReply *rs )
"to reference not allowed\n",
0, 0, 0 );
#endif
return( 1 );
rc = 1;
goto rel;
}
#ifdef LDAP_CONTROL_X_DOMAIN_SCOPE
......@@ -1255,8 +1261,8 @@ slap_send_search_reference( Operation *op, SlapReply *rs )
"send_search_reference: domainScope control in (%s)\n",
rs->sr_entry->e_dn, 0, 0 );
#endif
return( 0 );
rc = 0;
goto rel;
}
#endif
......@@ -1270,8 +1276,8 @@ slap_send_search_reference( Operation *op, SlapReply *rs )
"send_search_reference: null ref in (%s)\n",
rs->sr_entry ? rs->sr_entry->e_dn : "(null)", 0, 0 );
#endif
return( 1 );
rc = 1;
goto rel;
}
if( op->o_protocol < LDAP_VERSION3 ) {
......@@ -1280,7 +1286,8 @@ slap_send_search_reference( Operation *op, SlapReply *rs )
if( value_add( &rs->sr_v2ref, rs->sr_ref ) )
return LDAP_OTHER;
}
return 0;
rc = 0;
goto rel;
}
#ifdef LDAP_CONNECTIONLESS
......@@ -1288,7 +1295,10 @@ slap_send_search_reference( Operation *op, SlapReply *rs )
ber = op->o_res_ber;
else
#endif
ber_init_w_nullc( ber, LBER_USE_DER );
{
ber_init_w_nullc( ber, LBER_USE_DER );
ber_set_option( ber, LBER_OPT_BER_MEMCTX, op->o_tmpmemctx );
}
rc = ber_printf( ber, "{it{W}" /*"}"*/ , op->o_msgid,
LDAP_RES_SEARCH_REFERENCE, rs->sr_ref );
......@@ -1316,7 +1326,7 @@ slap_send_search_reference( Operation *op, SlapReply *rs )
#endif
ber_free_buf( ber );
send_ldap_error( op, rs, LDAP_OTHER, "encode DN error" );
return -1;
goto rel;
}
#ifdef LDAP_CONNECTIONLESS
......@@ -1344,7 +1354,9 @@ slap_send_search_reference( Operation *op, SlapReply *rs )
Debug( LDAP_DEBUG_TRACE, "<= send_search_reference\n", 0, 0, 0 );
#endif
return 0;
rel:
sl_release( mark, op->o_tmpmemctx );
return rc;
}
int
......
......@@ -235,6 +235,7 @@ int value_find_ex(
}
}
rc = LDAP_NO_SUCH_ATTRIBUTE;
for ( i = 0; vals[i].bv_val != NULL; i++ ) {
int match;
const char *text;
......@@ -243,11 +244,10 @@ int value_find_ex(
&vals[i], nval.bv_val == NULL ? val : &nval, &text );
if( rc == LDAP_SUCCESS && match == 0 ) {
free( nval.bv_val );
return LDAP_SUCCESS;
break;
}
}
ber_memfree_x( nval.bv_val, ctx );
return LDAP_NO_SUCH_ATTRIBUTE;
sl_free( nval.bv_val, ctx );
return rc;
}
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