+
+ BER_MEM_VALID( p );
+
+ if( ber_int_memory_fns == NULL ) {
+#ifdef LDAP_MEMORY_DEBUG
+ struct ber_mem_hdr *mh = (struct ber_mem_hdr *)
+ ((char *)p - sizeof(struct ber_mem_hdr));
+ assert( mh->bm_junk == BER_MEM_JUNK );
+
+ p = realloc( mh, s + sizeof(struct ber_mem_hdr) );
+
+ if( p == NULL ) return NULL;
+
+ mh = p;
+
+ assert( mh->bm_junk == BER_MEM_JUNK );
+
+ BER_MEM_VALID( &mh[1] );
+ return &mh[1];
+#else
+ return realloc( p, s );
+#endif
+ }
+
+ assert( ber_int_memory_fns->bmf_realloc );
+
+ return (*ber_int_memory_fns->bmf_realloc)( p, s );
+}
+
+
+void
+ber_bvfree( struct berval *bv )
+{
+ ber_int_options.lbo_valid = LBER_INITIALIZED;
+
+ if( bv == NULL ) {
+ return;
+ }
+
+ BER_MEM_VALID( bv );
+
+ if ( bv->bv_val != NULL )
+ LBER_FREE( bv->bv_val );
+
+ LBER_FREE( (char *) bv );
+}
+
+
+void
+ber_bvecfree( struct berval **bv )
+{
+ int i;
+
+ ber_int_options.lbo_valid = LBER_INITIALIZED;
+
+ if( bv == NULL ) {
+ return;
+ }
+
+ BER_MEM_VALID( bv );
+
+ for ( i = 0; bv[i] != NULL; i++ )
+ ber_bvfree( bv[i] );
+
+ LBER_FREE( (char *) bv );
+}
+
+
+struct berval *
+ber_bvdup(
+ LDAP_CONST struct berval *bv )
+{
+ struct berval *new;
+
+ ber_int_options.lbo_valid = LBER_INITIALIZED;
+
+ if( bv == NULL ) {
+ return NULL;
+ }
+
+ if(( new = LBER_MALLOC( sizeof(struct berval) )) == NULL ) {
+ return NULL;
+ }
+
+ if ( bv->bv_val == NULL ) {
+ new->bv_val = NULL;
+ new->bv_len = 0;
+ return new;
+ }
+
+ if(( new->bv_val = LBER_MALLOC( bv->bv_len + 1 )) == NULL ) {
+ LBER_FREE( new );
+ return NULL;
+ }
+
+ SAFEMEMCPY( new->bv_val, bv->bv_val, bv->bv_len );
+ new->bv_val[bv->bv_len] = '\0';
+ new->bv_len = bv->bv_len;
+
+ return( new );