From f7d7700b6e8b714ff83670eebb8022e3c98e6527 Mon Sep 17 00:00:00 2001 From: Howard Chu Date: Sun, 25 May 2003 01:32:39 +0000 Subject: [PATCH] ITS#2549, init memctx to NULL. Also reset ber memctx to NULL when freeing. --- servers/slapd/connection.c | 6 +++++- servers/slapd/operation.c | 4 ++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/servers/slapd/connection.c b/servers/slapd/connection.c index 90ba3505db..1c5281e340 100644 --- a/servers/slapd/connection.c +++ b/servers/slapd/connection.c @@ -892,7 +892,7 @@ connection_operation( void *ctx, void *arg_v ) ber_tag_t oldtag = tag; #endif /* SLAPD_MONITOR */ Connection *conn = op->o_conn; - void *memctx; + void *memctx = NULL; ber_len_t memsiz; ldap_pvt_thread_mutex_lock( &num_ops_mutex ); @@ -930,6 +930,10 @@ connection_operation( void *ctx, void *arg_v ) op->o_tmpmemctx = memctx; op->o_tmpmfuncs = &sl_mfuncs; if ( tag != LDAP_REQ_ADD && tag != LDAP_REQ_MODIFY ) { + /* Note - the ber and its buffer are already allocated from + * regular memory; this only affects subsequent mallocs that + * ber_scanf may invoke. + */ ber_set_option( op->o_ber, LBER_OPT_BER_MEMCTX, memctx ); } diff --git a/servers/slapd/operation.c b/servers/slapd/operation.c index 95e28288b5..537263b7d5 100644 --- a/servers/slapd/operation.c +++ b/servers/slapd/operation.c @@ -45,6 +45,10 @@ slap_op_free( Operation *op ) assert( LDAP_STAILQ_NEXT(op, o_next) == NULL ); if ( op->o_ber != NULL ) { + /* Note - the ber and its buffer are in regular memory, + * so make sure not to use sl_free here. + */ + ber_set_option( op->o_ber, LBER_OPT_BER_MEMCTX, NULL ); ber_free( op->o_ber, 1 ); } if ( op->o_dn.bv_val != NULL ) { -- 2.39.5