LDAP_FREE() -> ber_memfree(), msg->lm_ber -> ldap_get_message_ber(msg).
 
                if ( dnPretty( NULL, &match, &pmatch, op->o_tmpmemctx ) == LDAP_SUCCESS ) {
                        rs->sr_matched = pmatch.bv_val;
-                       LDAP_FREE( match.bv_val );
+                       ber_memfree( match.bv_val );
 
                } else {
                        rs->sr_matched = match.bv_val;
                        ber_memfree_x( (char *)rs->sr_matched, op->o_tmpmemctx );
 
                } else {
-                       LDAP_FREE( match.bv_val );
+                       ber_memfree( match.bv_val );
                }
                rs->sr_matched = save_matched;
        }
 
        if ( rs->sr_text ) {
                if ( freetext ) {
-                       LDAP_FREE( (char *)rs->sr_text );
+                       ber_memfree( (char *)rs->sr_text );
                }
                rs->sr_text = NULL;
        }
                struct berval   *bdn )
 {
        struct berval   a;
-       BerElement      ber = *e->lm_ber;
+       BerElement      ber = *ldap_get_message_ber( e );
        Attribute       *attr, **attrp;
        const char      *text;
        int             last;
 
 
                                ber_memfree_x( a_vals[ i ].bv_val, memctx );
                                ber_str2bv_x( newurl, 0, 1, &a_vals[ i ], memctx );
-                               LDAP_FREE( newurl );
+                               ber_memfree( newurl );
                                ludp->lud_dn = olddn.bv_val;
                        }
                        break;
 
        int                     check_duplicate_attrs = 0;
        int                     check_sorted_attrs = 0;
        Entry                   ent = { 0 };
-       BerElement              ber = *e->lm_ber;
+       BerElement              ber = *ldap_get_message_ber( e );
        Attribute               *attr, **attrp;
        struct berval           bdn,
                                dn = BER_BVNULL;
 
                                }
 
                                ber_str2bv( newurl, 0, 1, &a_vals[i] );
-                               LDAP_FREE( newurl );
+                               ber_memfree( newurl );
 
                                if ( pa_nvals ) {
                                        ludp->lud_dn = ndn.bv_val;
                                                ch_free( (*pa_nvals)[i].bv_val );
                                        }
                                        ber_str2bv( newurl, 0, 1, &(*pa_nvals)[i] );
-                                       LDAP_FREE( newurl );
+                                       ber_memfree( newurl );
                                }
 
                                ch_free( oldval.bv_val );
 
                                ch_free( a_vals[i].bv_val );
                                ber_str2bv( newurl, 0, 1, &a_vals[i] );
-                               LDAP_FREE( newurl );
+                               ber_memfree( newurl );
                                ludp->lud_dn = olddn.bv_val;
                        }
                        break;