int connections_destroy(void)
{
	ber_socket_t i;

	/* should check return of every call */

	if( connections == NULL) {
		Debug( LDAP_DEBUG_ANY, "connections_destroy: nothing to destroy.\n",
			0, 0, 0 );
		return -1;
	}

	for ( i = 0; i < dtblsize; i++ ) {
		if( connections[i].c_struct_state != SLAP_C_UNINITIALIZED ) {
			ber_sockbuf_free( connections[i].c_sb );
			ldap_pvt_thread_mutex_destroy( &connections[i].c_mutex );
			ldap_pvt_thread_mutex_destroy( &connections[i].c_write_mutex );
			ldap_pvt_thread_cond_destroy( &connections[i].c_write_cv );
#ifdef LDAP_SLAPI
			if ( slapi_plugins_used ) {
				slapi_int_free_object_extensions( SLAPI_X_EXT_CONNECTION,
					&connections[i] );
			}
#endif
		}
	}

	free( connections );
	connections = NULL;

	ldap_pvt_thread_mutex_destroy( &connections_mutex );
	ldap_pvt_thread_mutex_destroy( &conn_nextid_mutex );
	return 0;
}
示例#2
0
void
slap_op_free( Operation *op, void *ctx )
{
    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 );
    }
}
示例#3
0
文件: slapi_ops.c 项目: dago/openldap
void
slapi_int_connection_done_pb( Slapi_PBlock *pb )
{
	Connection		*conn;
	Operation		*op;

	PBLOCK_ASSERT_INTOP( pb, 0 );

	conn = pb->pb_conn;
	op = pb->pb_op;

	/* free allocated DNs */
	if ( !BER_BVISNULL( &op->o_dn ) )
		op->o_tmpfree( op->o_dn.bv_val, op->o_tmpmemctx );
	if ( !BER_BVISNULL( &op->o_ndn ) )
		op->o_tmpfree( op->o_ndn.bv_val, op->o_tmpmemctx );

	if ( !BER_BVISNULL( &op->o_req_dn ) )
		op->o_tmpfree( op->o_req_dn.bv_val, op->o_tmpmemctx );
	if ( !BER_BVISNULL( &op->o_req_ndn ) )
		op->o_tmpfree( op->o_req_ndn.bv_val, op->o_tmpmemctx );

	switch ( op->o_tag ) {
	case LDAP_REQ_MODRDN:
		if ( !BER_BVISNULL( &op->orr_newrdn ))
			op->o_tmpfree( op->orr_newrdn.bv_val, op->o_tmpmemctx );
		if ( !BER_BVISNULL( &op->orr_nnewrdn ))
			op->o_tmpfree( op->orr_nnewrdn.bv_val, op->o_tmpmemctx );
		if ( op->orr_newSup != NULL ) {
			assert( !BER_BVISNULL( op->orr_newSup ) );
			op->o_tmpfree( op->orr_newSup->bv_val, op->o_tmpmemctx );
			op->o_tmpfree( op->orr_newSup, op->o_tmpmemctx );
		}
		if ( op->orr_nnewSup != NULL ) {
			assert( !BER_BVISNULL( op->orr_nnewSup ) );
			op->o_tmpfree( op->orr_nnewSup->bv_val, op->o_tmpmemctx );
			op->o_tmpfree( op->orr_nnewSup, op->o_tmpmemctx );
		}
		slap_mods_free( op->orr_modlist, 1 );
		break;
	case LDAP_REQ_ADD:
		slap_mods_free( op->ora_modlist, 0 );
		break;
	case LDAP_REQ_MODIFY:
		slap_mods_free( op->orm_modlist, 1 );
		break;
	case LDAP_REQ_SEARCH:
		if ( op->ors_attrs != NULL ) {
			op->o_tmpfree( op->ors_attrs, op->o_tmpmemctx );
			op->ors_attrs = NULL;
		}
		break;
	default:
		break;
	}

	slapi_ch_free_string( &conn->c_authmech.bv_val );
	slapi_ch_free_string( &conn->c_dn.bv_val );
	slapi_ch_free_string( &conn->c_ndn.bv_val );
	slapi_ch_free_string( &conn->c_peer_domain.bv_val );
	slapi_ch_free_string( &conn->c_peer_name.bv_val );

	if ( conn->c_sb != NULL ) {
		ber_sockbuf_free( conn->c_sb );
	}

	slapi_int_free_object_extensions( SLAPI_X_EXT_OPERATION, op );
	slapi_int_free_object_extensions( SLAPI_X_EXT_CONNECTION, conn );

	slapi_ch_free( (void **)&pb->pb_op->o_callback );
	slapi_ch_free( (void **)&pb->pb_op );
	slapi_ch_free( (void **)&pb->pb_conn );
	slapi_ch_free( (void **)&pb->pb_rs );
}
示例#4
0
void
slap_op_free( Operation *op, void *ctx )
{
    OperationBuffer *opbuf;

    assert( LDAP_STAILQ_NEXT(op, o_next) == NULL );

    /* paranoia */
    op->o_abandon = 1;

    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 );
    }

    if ( op->o_pagedresults_state != NULL ) {
        op->o_tmpfree( op->o_pagedresults_state, op->o_tmpmemctx );
    }

    /* Selectively zero out the struct. Ignore fields that will
     * get explicitly initialized later anyway. Keep o_abandon intact.
     */
    opbuf = (OperationBuffer *) op;
    op->o_bd = NULL;
    BER_BVZERO( &op->o_req_dn );
    BER_BVZERO( &op->o_req_ndn );
    memset( op->o_hdr, 0, sizeof( *op->o_hdr ));
    memset( &op->o_request, 0, sizeof( op->o_request ));
    memset( &op->o_do_not_cache, 0, sizeof( Operation ) - offsetof( Operation, o_do_not_cache ));
    memset( opbuf->ob_controls, 0, sizeof( opbuf->ob_controls ));
    op->o_controls = opbuf->ob_controls;

    if ( ctx ) {
        Operation *op2 = NULL;
        ldap_pvt_thread_pool_setkey( ctx, (void *)slap_op_free,
                                     op, slap_op_q_destroy, (void **)&op2, NULL );
        LDAP_STAILQ_NEXT( op, o_next ) = op2;
        if ( op2 ) {
            op->o_tincr = op2->o_tincr + 1;
            /* No more than 10 ops on per-thread free list */
            if ( op->o_tincr > 10 ) {
                ldap_pvt_thread_pool_setkey( ctx, (void *)slap_op_free,
                                             op2, slap_op_q_destroy, NULL, NULL );
                ber_memfree_x( op, NULL );
            }
        } else {
            op->o_tincr = 1;
        }
    } else {
        ber_memfree_x( op, NULL );
    }
}