/* Walk up the tree from a child node, looking for an ID that's already
  * been linked into the cache.
  */
-static int
+int
 hdb_cache_find_parent(
        Operation *op,
        DB_TXN *txn,
 
                e->e_nname.bv_val = NULL;
        }
 #ifndef SLAP_ZONE_ALLOC
-#ifndef BDB_HIER
        /* In tool mode the e_bv buffer is realloc'd, leave it alone */
        if( !(slapMode & SLAP_TOOL_MODE) ) {
                free( e->e_bv.bv_val );
        }
-#else
-       free( e->e_bv.bv_val );
-#endif /* BDB_HIER */
 #endif /* !SLAP_ZONE_ALLOC */
 
 #ifdef SLAP_ZONE_ALLOC
 
 #define bdb_cache_find_id                      BDB_SYMBOL(cache_find_id)
 #define bdb_cache_find_info                    BDB_SYMBOL(cache_find_info)
 #define bdb_cache_find_ndn                     BDB_SYMBOL(cache_find_ndn)
+#define bdb_cache_find_parent          BDB_SYMBOL(cache_find_parent)
 #define bdb_cache_modify                       BDB_SYMBOL(cache_modify)
 #define bdb_cache_modrdn                       BDB_SYMBOL(cache_modrdn)
 #define bdb_cache_release_all          BDB_SYMBOL(cache_release_all)
        u_int32_t       locker,
        DB_LOCK         *lock
 );
+int
+bdb_cache_find_parent(
+       Operation *op,
+       DB_TXN *txn,
+       ID id,
+       EntryInfo **res
+);
 int bdb_cache_delete(
        Cache   *cache,
        Entry   *e,
 
 {
        int rc;
        Entry *e = NULL;
-#ifndef BDB_HIER
        struct berval bv;
-#endif
 
        assert( be != NULL );
        assert( slapMode & SLAP_TOOL_MODE );
        assert( data.data != NULL );
 
-#ifndef BDB_HIER
        DBT2bv( &data, &bv );
 
 #ifdef SLAP_ZONE_ALLOC
        if( rc == LDAP_SUCCESS ) {
                e->e_id = id;
        }
-#else
+#ifdef BDB_HIER
        {
                EntryInfo *ei = NULL;
                Operation op = {0};
                op.o_tmpmemctx = NULL;
                op.o_tmpmfuncs = &ch_mfuncs;
 
-               rc = bdb_cache_find_id( &op, NULL, id, &ei, 0, 0, NULL );
-               if ( rc == LDAP_SUCCESS )
-                       e = ei->bei_e;
+               rc = bdb_cache_find_parent( &op, NULL, id, &ei );
+               if ( rc == LDAP_SUCCESS ) {
+                       bdb_cache_entryinfo_unlock( ei );
+                       e->e_private = ei;
+                       ei->bei_e = e;
+                       bdb_fix_dn( e, 0 );
+                       ei->bei_e = NULL;
+                       e->e_private = NULL;
+               }
        }
 #endif
        return e;