+ if ( flags & SLAP_SET_REFVAL ) {
+ if ( ! ( flags & SLAP_SET_REFARR ) ) {
+ cp->set_op->o_tmpfree( set, cp->set_op->o_tmpmemctx );
+ }
+
+ } else {
+ ber_bvarray_free_x( set, cp->set_op->o_tmpmemctx );
+ }
+}
+
+static BerVarray
+set_dup( SetCookie *cp, BerVarray set, unsigned flags )
+{
+ BerVarray newset = NULL;
+
+ if ( set == NULL ) {
+ return NULL;
+ }
+
+ if ( flags & SLAP_SET_REFARR ) {
+ int i;
+
+ for ( i = 0; !BER_BVISNULL( &set[ i ] ); i++ )
+ ;
+ newset = cp->set_op->o_tmpcalloc( i + 1,
+ sizeof( struct berval ),
+ cp->set_op->o_tmpmemctx );
+ if ( newset == NULL ) {
+ return NULL;
+ }
+
+ if ( flags & SLAP_SET_REFVAL ) {
+ for ( i = 0; !BER_BVISNULL( &set[ i ] ); i++ ) {
+ ber_dupbv_x( &newset[ i ], &set[ i ],
+ cp->set_op->o_tmpmemctx );
+ }
+
+ } else {
+ AC_MEMCPY( newset, set, ( i + 1 ) * sizeof( struct berval ) );
+ }
+
+ } else {
+ newset = set;
+ }
+
+ return newset;