- Operation **tmp;
-
- for ( tmp = olist; *tmp != NULL; tmp = &(*tmp)->o_next )
- ; /* NULL */
-
- *tmp = (Operation *) calloc( 1, sizeof(Operation) );
- pthread_mutex_init( &(*tmp)->o_abandonmutex,
- pthread_mutexattr_default );
- (*tmp)->o_ber = ber;
- (*tmp)->o_msgid = msgid;
- (*tmp)->o_tag = tag;
- (*tmp)->o_abandon = 0;
- (*tmp)->o_dn = strdup( dn != NULL ? dn : "" );
- pthread_mutex_lock( ¤ttime_mutex );
- (*tmp)->o_time = currenttime;
- pthread_mutex_unlock( ¤ttime_mutex );
- (*tmp)->o_opid = id;
- (*tmp)->o_connid = connid;
- (*tmp)->o_next = NULL;
-
- return( *tmp );
+ OperationBuffer *opbuf;
+
+ assert( LDAP_STAILQ_NEXT(op, o_next) == NULL );
+
+ if ( op->o_ber != NULL ) {
+ ber_free( op->o_ber, 1 );
+ }
+ if ( !BER_BVISNULL( &op->o_dn ) ) {
+ ch_free( op->o_dn.bv_val );
+ }
+ if ( !BER_BVISNULL( &op->o_ndn ) ) {
+ ch_free( op->o_ndn.bv_val );
+ }
+ if ( !BER_BVISNULL( &op->o_authmech ) ) {
+ ch_free( op->o_authmech.bv_val );
+ }
+ if ( op->o_ctrls != NULL ) {
+ slap_free_ctrls( op, op->o_ctrls );
+ }
+
+#ifdef LDAP_CONNECTIONLESS
+ if ( op->o_res_ber != NULL ) {
+ ber_free( op->o_res_ber, 1 );
+ }
+#endif
+
+ if ( op->o_groups ) {
+ slap_op_groups_free( op );
+ }
+
+#if defined( LDAP_SLAPI )
+ if ( slapi_plugins_used ) {
+ slapi_int_free_object_extensions( SLAPI_X_EXT_OPERATION, op );
+ }
+#endif /* defined( LDAP_SLAPI ) */
+
+ if ( !BER_BVISNULL( &op->o_csn ) ) {
+ op->o_tmpfree( op->o_csn.bv_val, op->o_tmpmemctx );
+ BER_BVZERO( &op->o_csn );
+ }
+
+ opbuf = (OperationBuffer *) op;
+ memset( opbuf, 0, sizeof(*opbuf) );
+ op->o_hdr = &opbuf->ob_hdr;
+ op->o_controls = opbuf->ob_controls;
+
+ if ( ctx ) {
+ void *op2 = NULL;
+ ldap_pvt_thread_pool_setkey( ctx, (void *)slap_op_free,
+ op, slap_op_q_destroy, &op2, NULL );
+ LDAP_STAILQ_NEXT( op, o_next ) = op2;
+ } else {
+ ber_memfree_x( op, NULL );
+ }