andykimpe / rpms / 389-ds-base

Forked from rpms/389-ds-base 5 months ago
Clone

Blame SOURCES/0004-Issue-51076-remove-unnecessary-slapi-entry-dups.patch

d69b2b
From f13d630ff98eb5b5505f1db3e7f207175b51b237 Mon Sep 17 00:00:00 2001
d69b2b
From: Mark Reynolds <mreynolds@redhat.com>
d69b2b
Date: Tue, 12 May 2020 13:48:30 -0400
d69b2b
Subject: [PATCH 04/12] Issue 51076 - remove unnecessary slapi entry dups
d69b2b
d69b2b
Description:  So the problem is that slapi_search_internal_get_entry()
d69b2b
              duplicates the entry twice.  It does that as a convenience
d69b2b
              where it will allocate a pblock, do the search, copy
d69b2b
              the entry, free search results from the pblock, and then
d69b2b
              free the pblock itself.  I basically split this function
d69b2b
              into two functions.  One function allocates the pblock,
d69b2b
              does the search and returns the entry.  The other function
d69b2b
              frees the entries and pblock.
d69b2b
d69b2b
              99% of time when we call slapi_search_internal_get_entry()
d69b2b
              we are just reading it and freeing it.  It's not being
d69b2b
              consumed.  In these cases we can use the two function
d69b2b
              approach eliminates an extra slapi_entry_dup().  Over the
d69b2b
              time of an operation/connection we can save quite a bit
d69b2b
              of mallocing/freeing.  This could also help with memory
d69b2b
              fragmentation.
d69b2b
d69b2b
ASAN: passed
d69b2b
d69b2b
relates: https://pagure.io/389-ds-base/issue/51076
d69b2b
d69b2b
Reviewed by: firstyear & tbordaz(Thanks!)
d69b2b
---
d69b2b
 ldap/servers/plugins/acctpolicy/acct_config.c |  6 +--
d69b2b
 ldap/servers/plugins/acctpolicy/acct_plugin.c | 36 +++++++-------
d69b2b
 ldap/servers/plugins/acctpolicy/acct_util.c   |  6 +--
d69b2b
 ldap/servers/plugins/automember/automember.c  | 17 +++----
d69b2b
 ldap/servers/plugins/dna/dna.c                | 23 ++++-----
d69b2b
 ldap/servers/plugins/memberof/memberof.c      | 16 +++----
d69b2b
 .../plugins/pam_passthru/pam_ptconfig.c       | 10 ++--
d69b2b
 .../servers/plugins/pam_passthru/pam_ptimpl.c |  7 +--
d69b2b
 .../plugins/pam_passthru/pam_ptpreop.c        |  9 ++--
d69b2b
 .../plugins/replication/repl5_tot_protocol.c  |  5 +-
d69b2b
 ldap/servers/plugins/uiduniq/uid.c            | 23 ++++-----
d69b2b
 ldap/servers/slapd/daemon.c                   | 11 ++---
d69b2b
 ldap/servers/slapd/modify.c                   | 12 +++--
d69b2b
 ldap/servers/slapd/plugin_internal_op.c       | 48 +++++++++++++++++++
d69b2b
 ldap/servers/slapd/resourcelimit.c            | 13 ++---
d69b2b
 ldap/servers/slapd/schema.c                   |  7 ++-
d69b2b
 ldap/servers/slapd/slapi-plugin.h             | 23 ++++++++-
d69b2b
 17 files changed, 161 insertions(+), 111 deletions(-)
d69b2b
d69b2b
diff --git a/ldap/servers/plugins/acctpolicy/acct_config.c b/ldap/servers/plugins/acctpolicy/acct_config.c
d69b2b
index fe35ba5a0..01e4f319f 100644
d69b2b
--- a/ldap/servers/plugins/acctpolicy/acct_config.c
d69b2b
+++ b/ldap/servers/plugins/acctpolicy/acct_config.c
d69b2b
@@ -37,6 +37,7 @@ static int acct_policy_entry2config(Slapi_Entry *e,
d69b2b
 int
d69b2b
 acct_policy_load_config_startup(Slapi_PBlock *pb __attribute__((unused)), void *plugin_id)
d69b2b
 {
d69b2b
+    Slapi_PBlock *entry_pb = NULL;
d69b2b
     acctPluginCfg *newcfg;
d69b2b
     Slapi_Entry *config_entry = NULL;
d69b2b
     Slapi_DN *config_sdn = NULL;
d69b2b
@@ -44,8 +45,7 @@ acct_policy_load_config_startup(Slapi_PBlock *pb __attribute__((unused)), void *
d69b2b
 
d69b2b
     /* Retrieve the config entry */
d69b2b
     config_sdn = slapi_sdn_new_normdn_byref(PLUGIN_CONFIG_DN);
d69b2b
-    rc = slapi_search_internal_get_entry(config_sdn, NULL, &config_entry,
d69b2b
-                                         plugin_id);
d69b2b
+    rc = slapi_search_get_entry(&entry_pb, config_sdn, NULL, &config_entry, plugin_id);
d69b2b
     slapi_sdn_free(&config_sdn);
d69b2b
 
d69b2b
     if (rc != LDAP_SUCCESS || config_entry == NULL) {
d69b2b
@@ -60,7 +60,7 @@ acct_policy_load_config_startup(Slapi_PBlock *pb __attribute__((unused)), void *
d69b2b
     rc = acct_policy_entry2config(config_entry, newcfg);
d69b2b
     config_unlock();
d69b2b
 
d69b2b
-    slapi_entry_free(config_entry);
d69b2b
+    slapi_search_get_entry_done(&entry_pb);
d69b2b
 
d69b2b
     return (rc);
d69b2b
 }
d69b2b
diff --git a/ldap/servers/plugins/acctpolicy/acct_plugin.c b/ldap/servers/plugins/acctpolicy/acct_plugin.c
d69b2b
index 2a876ad72..c3c32b074 100644
d69b2b
--- a/ldap/servers/plugins/acctpolicy/acct_plugin.c
d69b2b
+++ b/ldap/servers/plugins/acctpolicy/acct_plugin.c
d69b2b
@@ -209,6 +209,7 @@ done:
d69b2b
 int
d69b2b
 acct_bind_preop(Slapi_PBlock *pb)
d69b2b
 {
d69b2b
+    Slapi_PBlock *entry_pb = NULL;
d69b2b
     const char *dn = NULL;
d69b2b
     Slapi_DN *sdn = NULL;
d69b2b
     Slapi_Entry *target_entry = NULL;
d69b2b
@@ -236,8 +237,7 @@ acct_bind_preop(Slapi_PBlock *pb)
d69b2b
         goto done;
d69b2b
     }
d69b2b
 
d69b2b
-    ldrc = slapi_search_internal_get_entry(sdn, NULL, &target_entry,
d69b2b
-                                           plugin_id);
d69b2b
+    ldrc = slapi_search_get_entry(&entry_pb, sdn, NULL, &target_entry, plugin_id);
d69b2b
 
d69b2b
     /* There was a problem retrieving the entry */
d69b2b
     if (ldrc != LDAP_SUCCESS) {
d69b2b
@@ -275,7 +275,7 @@ done:
d69b2b
         slapi_send_ldap_result(pb, LDAP_UNWILLING_TO_PERFORM, NULL, NULL, 0, NULL);
d69b2b
     }
d69b2b
 
d69b2b
-    slapi_entry_free(target_entry);
d69b2b
+    slapi_search_get_entry_done(&entry_pb);
d69b2b
 
d69b2b
     free_acctpolicy(&policy);
d69b2b
 
d69b2b
@@ -293,6 +293,7 @@ done:
d69b2b
 int
d69b2b
 acct_bind_postop(Slapi_PBlock *pb)
d69b2b
 {
d69b2b
+    Slapi_PBlock *entry_pb = NULL;
d69b2b
     char *dn = NULL;
d69b2b
     int ldrc, tracklogin = 0;
d69b2b
     int rc = 0; /* Optimistic default */
d69b2b
@@ -327,8 +328,7 @@ acct_bind_postop(Slapi_PBlock *pb)
d69b2b
        covered by an account policy to decide whether we should track */
d69b2b
     if (tracklogin == 0) {
d69b2b
         sdn = slapi_sdn_new_normdn_byref(dn);
d69b2b
-        ldrc = slapi_search_internal_get_entry(sdn, NULL, &target_entry,
d69b2b
-                                               plugin_id);
d69b2b
+        ldrc = slapi_search_get_entry(&entry_pb, sdn, NULL, &target_entry, plugin_id);
d69b2b
 
d69b2b
         if (ldrc != LDAP_SUCCESS) {
d69b2b
             slapi_log_err(SLAPI_LOG_ERR, POST_PLUGIN_NAME,
d69b2b
@@ -355,7 +355,7 @@ done:
d69b2b
         slapi_send_ldap_result(pb, LDAP_UNWILLING_TO_PERFORM, NULL, NULL, 0, NULL);
d69b2b
     }
d69b2b
 
d69b2b
-    slapi_entry_free(target_entry);
d69b2b
+    slapi_search_get_entry_done(&entry_pb);
d69b2b
 
d69b2b
     slapi_sdn_free(&sdn;;
d69b2b
 
d69b2b
@@ -370,11 +370,11 @@ done:
d69b2b
 static int
d69b2b
 acct_pre_op(Slapi_PBlock *pb, int modop)
d69b2b
 {
d69b2b
+    Slapi_PBlock *entry_pb = NULL;
d69b2b
     Slapi_DN *sdn = 0;
d69b2b
     Slapi_Entry *e = 0;
d69b2b
     Slapi_Mods *smods = 0;
d69b2b
     LDAPMod **mods;
d69b2b
-    int free_entry = 0;
d69b2b
     char *errstr = NULL;
d69b2b
     int ret = SLAPI_PLUGIN_SUCCESS;
d69b2b
 
d69b2b
@@ -384,28 +384,25 @@ acct_pre_op(Slapi_PBlock *pb, int modop)
d69b2b
 
d69b2b
     if (acct_policy_dn_is_config(sdn)) {
d69b2b
         /* Validate config changes, but don't apply them.
d69b2b
-     * This allows us to reject invalid config changes
d69b2b
-     * here at the pre-op stage.  Applying the config
d69b2b
-     * needs to be done at the post-op stage. */
d69b2b
+         * This allows us to reject invalid config changes
d69b2b
+         * here at the pre-op stage.  Applying the config
d69b2b
+         * needs to be done at the post-op stage. */
d69b2b
 
d69b2b
         if (LDAP_CHANGETYPE_ADD == modop) {
d69b2b
             slapi_pblock_get(pb, SLAPI_ADD_ENTRY, &e);
d69b2b
 
d69b2b
-            /* If the entry doesn't exist, just bail and
d69b2b
-     * let the server handle it. */
d69b2b
+            /* If the entry doesn't exist, just bail and let the server handle it. */
d69b2b
             if (e == NULL) {
d69b2b
                 goto bail;
d69b2b
             }
d69b2b
         } else if (LDAP_CHANGETYPE_MODIFY == modop) {
d69b2b
             /* Fetch the entry being modified so we can
d69b2b
-     * create the resulting entry for validation. */
d69b2b
+             * create the resulting entry for validation. */
d69b2b
             if (sdn) {
d69b2b
-                slapi_search_internal_get_entry(sdn, 0, &e, get_identity());
d69b2b
-                free_entry = 1;
d69b2b
+                slapi_search_get_entry(&entry_pb, sdn, 0, &e, get_identity());
d69b2b
             }
d69b2b
 
d69b2b
-            /* If the entry doesn't exist, just bail and
d69b2b
-     * let the server handle it. */
d69b2b
+            /* If the entry doesn't exist, just bail and let the server handle it. */
d69b2b
             if (e == NULL) {
d69b2b
                 goto bail;
d69b2b
             }
d69b2b
@@ -418,7 +415,7 @@ acct_pre_op(Slapi_PBlock *pb, int modop)
d69b2b
             /* Apply the  mods to create the resulting entry. */
d69b2b
             if (mods && (slapi_entry_apply_mods(e, mods) != LDAP_SUCCESS)) {
d69b2b
                 /* The mods don't apply cleanly, so we just let this op go
d69b2b
-     * to let the main server handle it. */
d69b2b
+                 * to let the main server handle it. */
d69b2b
                 goto bailmod;
d69b2b
             }
d69b2b
         } else if (modop == LDAP_CHANGETYPE_DELETE) {
d69b2b
@@ -439,8 +436,7 @@ bailmod:
d69b2b
     }
d69b2b
 
d69b2b
 bail:
d69b2b
-    if (free_entry && e)
d69b2b
-        slapi_entry_free(e);
d69b2b
+    slapi_search_get_entry_done(&entry_pb);
d69b2b
 
d69b2b
     if (ret) {
d69b2b
         slapi_log_err(SLAPI_LOG_PLUGIN, PRE_PLUGIN_NAME,
d69b2b
diff --git a/ldap/servers/plugins/acctpolicy/acct_util.c b/ldap/servers/plugins/acctpolicy/acct_util.c
d69b2b
index f25a3202d..f432092fe 100644
d69b2b
--- a/ldap/servers/plugins/acctpolicy/acct_util.c
d69b2b
+++ b/ldap/servers/plugins/acctpolicy/acct_util.c
d69b2b
@@ -85,6 +85,7 @@ get_attr_string_val(Slapi_Entry *target_entry, char *attr_name)
d69b2b
 int
d69b2b
 get_acctpolicy(Slapi_PBlock *pb __attribute__((unused)), Slapi_Entry *target_entry, void *plugin_id, acctPolicy **policy)
d69b2b
 {
d69b2b
+    Slapi_PBlock *entry_pb = NULL;
d69b2b
     Slapi_DN *sdn = NULL;
d69b2b
     Slapi_Entry *policy_entry = NULL;
d69b2b
     Slapi_Attr *attr;
d69b2b
@@ -123,8 +124,7 @@ get_acctpolicy(Slapi_PBlock *pb __attribute__((unused)), Slapi_Entry *target_ent
d69b2b
     }
d69b2b
 
d69b2b
     sdn = slapi_sdn_new_dn_byref(policy_dn);
d69b2b
-    ldrc = slapi_search_internal_get_entry(sdn, NULL, &policy_entry,
d69b2b
-                                           plugin_id);
d69b2b
+    ldrc = slapi_search_get_entry(&entry_pb, sdn, NULL, &policy_entry, plugin_id);
d69b2b
     slapi_sdn_free(&sdn;;
d69b2b
 
d69b2b
     /* There should be a policy but it can't be retrieved; fatal error */
d69b2b
@@ -160,7 +160,7 @@ dopolicy:
d69b2b
 done:
d69b2b
     config_unlock();
d69b2b
     slapi_ch_free_string(&policy_dn);
d69b2b
-    slapi_entry_free(policy_entry);
d69b2b
+    slapi_search_get_entry_done(&entry_pb);
d69b2b
     return (rc);
d69b2b
 }
d69b2b
 
d69b2b
diff --git a/ldap/servers/plugins/automember/automember.c b/ldap/servers/plugins/automember/automember.c
d69b2b
index 7c875c852..39350ad53 100644
d69b2b
--- a/ldap/servers/plugins/automember/automember.c
d69b2b
+++ b/ldap/servers/plugins/automember/automember.c
d69b2b
@@ -1629,13 +1629,12 @@ automember_update_member_value(Slapi_Entry *member_e, const char *group_dn, char
d69b2b
     char *member_value = NULL;
d69b2b
     int rc = 0;
d69b2b
     Slapi_DN *group_sdn;
d69b2b
-    Slapi_Entry *group_entry = NULL;
d69b2b
 
d69b2b
     /* First thing check that the group still exists */
d69b2b
     group_sdn = slapi_sdn_new_dn_byval(group_dn);
d69b2b
-    rc = slapi_search_internal_get_entry(group_sdn, NULL, &group_entry, automember_get_plugin_id());
d69b2b
+    rc = slapi_search_internal_get_entry(group_sdn, NULL, NULL, automember_get_plugin_id());
d69b2b
     slapi_sdn_free(&group_sdn);
d69b2b
-    if (rc != LDAP_SUCCESS || group_entry == NULL) {
d69b2b
+    if (rc != LDAP_SUCCESS) {
d69b2b
         if (rc == LDAP_NO_SUCH_OBJECT) {
d69b2b
             /* the automember group (default or target) does not exist, just skip this definition */
d69b2b
             slapi_log_err(SLAPI_LOG_INFO, AUTOMEMBER_PLUGIN_SUBSYSTEM,
d69b2b
@@ -1647,10 +1646,8 @@ automember_update_member_value(Slapi_Entry *member_e, const char *group_dn, char
d69b2b
                       "automember_update_member_value - group (default or target) can not be retrieved (%s) err=%d\n",
d69b2b
                       group_dn, rc);
d69b2b
         }
d69b2b
-        slapi_entry_free(group_entry);
d69b2b
         return rc;
d69b2b
     }
d69b2b
-    slapi_entry_free(group_entry);
d69b2b
 
d69b2b
     /* If grouping_value is dn, we need to fetch the dn instead. */
d69b2b
     if (slapi_attr_type_cmp(grouping_value, "dn", SLAPI_TYPE_CMP_EXACT) == 0) {
d69b2b
@@ -1752,11 +1749,11 @@ out:
d69b2b
 static int
d69b2b
 automember_pre_op(Slapi_PBlock *pb, int modop)
d69b2b
 {
d69b2b
+    Slapi_PBlock *entry_pb = NULL;
d69b2b
     Slapi_DN *sdn = 0;
d69b2b
     Slapi_Entry *e = 0;
d69b2b
     Slapi_Mods *smods = 0;
d69b2b
     LDAPMod **mods;
d69b2b
-    int free_entry = 0;
d69b2b
     char *errstr = NULL;
d69b2b
     int ret = SLAPI_PLUGIN_SUCCESS;
d69b2b
 
d69b2b
@@ -1784,8 +1781,7 @@ automember_pre_op(Slapi_PBlock *pb, int modop)
d69b2b
             /* Fetch the entry being modified so we can
d69b2b
              * create the resulting entry for validation. */
d69b2b
             if (sdn) {
d69b2b
-                slapi_search_internal_get_entry(sdn, 0, &e, automember_get_plugin_id());
d69b2b
-                free_entry = 1;
d69b2b
+                slapi_search_get_entry(&entry_pb, sdn, 0, &e, automember_get_plugin_id());
d69b2b
             }
d69b2b
 
d69b2b
             /* If the entry doesn't exist, just bail and
d69b2b
@@ -1799,7 +1795,7 @@ automember_pre_op(Slapi_PBlock *pb, int modop)
d69b2b
             smods = slapi_mods_new();
d69b2b
             slapi_mods_init_byref(smods, mods);
d69b2b
 
d69b2b
-            /* Apply the  mods to create the resulting entry. */
d69b2b
+            /* Apply the mods to create the resulting entry. */
d69b2b
             if (mods && (slapi_entry_apply_mods(e, mods) != LDAP_SUCCESS)) {
d69b2b
                 /* The mods don't apply cleanly, so we just let this op go
d69b2b
                  * to let the main server handle it. */
d69b2b
@@ -1831,8 +1827,7 @@ bailmod:
d69b2b
     }
d69b2b
 
d69b2b
 bail:
d69b2b
-    if (free_entry && e)
d69b2b
-        slapi_entry_free(e);
d69b2b
+    slapi_search_get_entry_done(&entry_pb);
d69b2b
 
d69b2b
     if (ret) {
d69b2b
         slapi_log_err(SLAPI_LOG_PLUGIN, AUTOMEMBER_PLUGIN_SUBSYSTEM,
d69b2b
diff --git a/ldap/servers/plugins/dna/dna.c b/ldap/servers/plugins/dna/dna.c
d69b2b
index 1ee271359..16c625bb0 100644
d69b2b
--- a/ldap/servers/plugins/dna/dna.c
d69b2b
+++ b/ldap/servers/plugins/dna/dna.c
d69b2b
@@ -1178,7 +1178,6 @@ dna_parse_config_entry(Slapi_PBlock *pb, Slapi_Entry *e, int apply)
d69b2b
 
d69b2b
     value = slapi_entry_attr_get_charptr(e, DNA_SHARED_CFG_DN);
d69b2b
     if (value) {
d69b2b
-        Slapi_Entry *shared_e = NULL;
d69b2b
         Slapi_DN *sdn = NULL;
d69b2b
         char *normdn = NULL;
d69b2b
         char *attrs[2];
d69b2b
@@ -1197,10 +1196,8 @@ dna_parse_config_entry(Slapi_PBlock *pb, Slapi_Entry *e, int apply)
d69b2b
         /* We don't need attributes */
d69b2b
         attrs[0] = "cn";
d69b2b
         attrs[1] = NULL;
d69b2b
-        slapi_search_internal_get_entry(sdn, attrs, &shared_e, getPluginID());
d69b2b
-
d69b2b
         /* Make sure that the shared config entry exists. */
d69b2b
-        if (!shared_e) {
d69b2b
+        if(slapi_search_internal_get_entry(sdn, attrs, NULL, getPluginID()) != LDAP_SUCCESS) {
d69b2b
             /* We didn't locate the shared config container entry. Log
d69b2b
              * a message and skip this config entry. */
d69b2b
             slapi_log_err(SLAPI_LOG_ERR, DNA_PLUGIN_SUBSYSTEM,
d69b2b
@@ -1210,9 +1207,6 @@ dna_parse_config_entry(Slapi_PBlock *pb, Slapi_Entry *e, int apply)
d69b2b
             ret = DNA_FAILURE;
d69b2b
             slapi_sdn_free(&sdn;;
d69b2b
             goto bail;
d69b2b
-        } else {
d69b2b
-            slapi_entry_free(shared_e);
d69b2b
-            shared_e = NULL;
d69b2b
         }
d69b2b
 
d69b2b
         normdn = (char *)slapi_sdn_get_dn(sdn);
d69b2b
@@ -1539,6 +1533,7 @@ dna_delete_shared_servers(PRCList **servers)
d69b2b
 static int
d69b2b
 dna_load_host_port(void)
d69b2b
 {
d69b2b
+    Slapi_PBlock *pb = NULL;
d69b2b
     int status = DNA_SUCCESS;
d69b2b
     Slapi_Entry *e = NULL;
d69b2b
     Slapi_DN *config_dn = NULL;
d69b2b
@@ -1554,7 +1549,7 @@ dna_load_host_port(void)
d69b2b
 
d69b2b
     config_dn = slapi_sdn_new_ndn_byref("cn=config");
d69b2b
     if (config_dn) {
d69b2b
-        slapi_search_internal_get_entry(config_dn, attrs, &e, getPluginID());
d69b2b
+        slapi_search_get_entry(&pb, config_dn, attrs, &e, getPluginID());
d69b2b
         slapi_sdn_free(&config_dn);
d69b2b
     }
d69b2b
 
d69b2b
@@ -1562,8 +1557,8 @@ dna_load_host_port(void)
d69b2b
         hostname = slapi_entry_attr_get_charptr(e, "nsslapd-localhost");
d69b2b
         portnum = slapi_entry_attr_get_charptr(e, "nsslapd-port");
d69b2b
         secureportnum = slapi_entry_attr_get_charptr(e, "nsslapd-secureport");
d69b2b
-        slapi_entry_free(e);
d69b2b
     }
d69b2b
+    slapi_search_get_entry_done(&pb;;
d69b2b
 
d69b2b
     if (!hostname || !portnum) {
d69b2b
         status = DNA_FAILURE;
d69b2b
@@ -2876,6 +2871,7 @@ bail:
d69b2b
 static int
d69b2b
 dna_is_replica_bind_dn(char *range_dn, char *bind_dn)
d69b2b
 {
d69b2b
+    Slapi_PBlock *entry_pb = NULL;
d69b2b
     char *replica_dn = NULL;
d69b2b
     Slapi_DN *replica_sdn = NULL;
d69b2b
     Slapi_DN *range_sdn = NULL;
d69b2b
@@ -2912,8 +2908,7 @@ dna_is_replica_bind_dn(char *range_dn, char *bind_dn)
d69b2b
         attrs[2] = 0;
d69b2b
 
d69b2b
         /* Find cn=replica entry via search */
d69b2b
-        slapi_search_internal_get_entry(replica_sdn, attrs, &e, getPluginID());
d69b2b
-
d69b2b
+        slapi_search_get_entry(&entry_pb, replica_sdn, attrs, &e, getPluginID());
d69b2b
         if (e) {
d69b2b
             /* Check if the passed in bind dn matches any of the replica bind dns. */
d69b2b
             Slapi_Value *bind_dn_sv = slapi_value_new_string(bind_dn);
d69b2b
@@ -2927,6 +2922,7 @@ dna_is_replica_bind_dn(char *range_dn, char *bind_dn)
d69b2b
                 attrs[0] = "member";
d69b2b
                 attrs[1] = "uniquemember";
d69b2b
                 attrs[2] = 0;
d69b2b
+                slapi_search_get_entry_done(&entry_pb);
d69b2b
                 for (i = 0; bind_group_dn != NULL && bind_group_dn[i] != NULL; i++) {
d69b2b
                     if (ret) {
d69b2b
                         /* already found a member, just free group */
d69b2b
@@ -2934,14 +2930,14 @@ dna_is_replica_bind_dn(char *range_dn, char *bind_dn)
d69b2b
                         continue;
d69b2b
                     }
d69b2b
                     bind_group_sdn = slapi_sdn_new_normdn_passin(bind_group_dn[i]);
d69b2b
-                    slapi_search_internal_get_entry(bind_group_sdn, attrs, &bind_group_entry, getPluginID());
d69b2b
+                    slapi_search_get_entry(&entry_pb, bind_group_sdn, attrs, &bind_group_entry, getPluginID());
d69b2b
                     if (bind_group_entry) {
d69b2b
                         ret = slapi_entry_attr_has_syntax_value(bind_group_entry, "member", bind_dn_sv);
d69b2b
                         if (ret == 0) {
d69b2b
                             ret = slapi_entry_attr_has_syntax_value(bind_group_entry, "uniquemember", bind_dn_sv);
d69b2b
                         }
d69b2b
                     }
d69b2b
-                    slapi_entry_free(bind_group_entry);
d69b2b
+                    slapi_search_get_entry_done(&entry_pb);
d69b2b
                     slapi_sdn_free(&bind_group_sdn);
d69b2b
                 }
d69b2b
                 slapi_ch_free((void **)&bind_group_dn);
d69b2b
@@ -2956,7 +2952,6 @@ dna_is_replica_bind_dn(char *range_dn, char *bind_dn)
d69b2b
     }
d69b2b
 
d69b2b
 done:
d69b2b
-    slapi_entry_free(e);
d69b2b
     slapi_sdn_free(&range_sdn);
d69b2b
     slapi_sdn_free(&replica_sdn);
d69b2b
 
d69b2b
diff --git a/ldap/servers/plugins/memberof/memberof.c b/ldap/servers/plugins/memberof/memberof.c
d69b2b
index 40bd4b380..e9e1ec4c7 100644
d69b2b
--- a/ldap/servers/plugins/memberof/memberof.c
d69b2b
+++ b/ldap/servers/plugins/memberof/memberof.c
d69b2b
@@ -884,7 +884,7 @@ memberof_postop_modrdn(Slapi_PBlock *pb)
d69b2b
             pre_sdn = slapi_entry_get_sdn(pre_e);
d69b2b
             post_sdn = slapi_entry_get_sdn(post_e);
d69b2b
         }
d69b2b
-        
d69b2b
+
d69b2b
         if (pre_sdn && post_sdn && slapi_sdn_compare(pre_sdn, post_sdn) == 0) {
d69b2b
             /* Regarding memberof plugin, this rename is a no-op
d69b2b
              * but it can be expensive to process it. So skip it
d69b2b
@@ -1466,6 +1466,7 @@ memberof_modop_one_r(Slapi_PBlock *pb, MemberOfConfig *config, int mod_op, Slapi
d69b2b
 int
d69b2b
 memberof_modop_one_replace_r(Slapi_PBlock *pb, MemberOfConfig *config, int mod_op, Slapi_DN *group_sdn, Slapi_DN *op_this_sdn, Slapi_DN *replace_with_sdn, Slapi_DN *op_to_sdn, memberofstringll *stack)
d69b2b
 {
d69b2b
+    Slapi_PBlock *entry_pb = NULL;
d69b2b
     int rc = 0;
d69b2b
     LDAPMod mod;
d69b2b
     LDAPMod replace_mod;
d69b2b
@@ -1515,8 +1516,7 @@ memberof_modop_one_replace_r(Slapi_PBlock *pb, MemberOfConfig *config, int mod_o
d69b2b
     }
d69b2b
 
d69b2b
     /* determine if this is a group op or single entry */
d69b2b
-    slapi_search_internal_get_entry(op_to_sdn, config->groupattrs,
d69b2b
-                                    &e, memberof_get_plugin_id());
d69b2b
+    slapi_search_get_entry(&entry_pb, op_to_sdn, config->groupattrs, &e, memberof_get_plugin_id());
d69b2b
     if (!e) {
d69b2b
         /* In the case of a delete, we need to worry about the
d69b2b
          * missing entry being a nested group.  There's a small
d69b2b
@@ -1751,7 +1751,7 @@ memberof_modop_one_replace_r(Slapi_PBlock *pb, MemberOfConfig *config, int mod_o
d69b2b
 bail:
d69b2b
     slapi_value_free(&to_dn_val);
d69b2b
     slapi_value_free(&this_dn_val);
d69b2b
-    slapi_entry_free(e);
d69b2b
+    slapi_search_get_entry_done(&entry_pb);
d69b2b
     return rc;
d69b2b
 }
d69b2b
 
d69b2b
@@ -2368,6 +2368,7 @@ bail:
d69b2b
 int
d69b2b
 memberof_is_direct_member(MemberOfConfig *config, Slapi_Value *groupdn, Slapi_Value *memberdn)
d69b2b
 {
d69b2b
+    Slapi_PBlock *pb = NULL;
d69b2b
     int rc = 0;
d69b2b
     Slapi_DN *sdn = 0;
d69b2b
     Slapi_Entry *group_e = 0;
d69b2b
@@ -2376,8 +2377,8 @@ memberof_is_direct_member(MemberOfConfig *config, Slapi_Value *groupdn, Slapi_Va
d69b2b
 
d69b2b
     sdn = slapi_sdn_new_normdn_byref(slapi_value_get_string(groupdn));
d69b2b
 
d69b2b
-    slapi_search_internal_get_entry(sdn, config->groupattrs,
d69b2b
-                                    &group_e, memberof_get_plugin_id());
d69b2b
+    slapi_search_get_entry(&pb, sdn, config->groupattrs,
d69b2b
+                           &group_e, memberof_get_plugin_id());
d69b2b
 
d69b2b
     if (group_e) {
d69b2b
         /* See if memberdn is referred to by any of the group attributes. */
d69b2b
@@ -2388,9 +2389,8 @@ memberof_is_direct_member(MemberOfConfig *config, Slapi_Value *groupdn, Slapi_Va
d69b2b
                 break;
d69b2b
             }
d69b2b
         }
d69b2b
-
d69b2b
-        slapi_entry_free(group_e);
d69b2b
     }
d69b2b
+    slapi_search_get_entry_done(&pb;;
d69b2b
 
d69b2b
     slapi_sdn_free(&sdn;;
d69b2b
     return rc;
d69b2b
diff --git a/ldap/servers/plugins/pam_passthru/pam_ptconfig.c b/ldap/servers/plugins/pam_passthru/pam_ptconfig.c
d69b2b
index 46a76d884..cbec2ec40 100644
d69b2b
--- a/ldap/servers/plugins/pam_passthru/pam_ptconfig.c
d69b2b
+++ b/ldap/servers/plugins/pam_passthru/pam_ptconfig.c
d69b2b
@@ -749,22 +749,22 @@ pam_passthru_get_config(Slapi_DN *bind_sdn)
d69b2b
             if (pam_passthru_check_suffix(cfg, bind_sdn) == LDAP_SUCCESS) {
d69b2b
                 if (cfg->slapi_filter) {
d69b2b
                     /* A filter is configured, so see if the bind entry is a match. */
d69b2b
+                    Slapi_PBlock *entry_pb = NULL;
d69b2b
                     Slapi_Entry *test_e = NULL;
d69b2b
 
d69b2b
                     /* Fetch the bind entry */
d69b2b
-                    slapi_search_internal_get_entry(bind_sdn, NULL, &test_e,
d69b2b
-                                                    pam_passthruauth_get_plugin_identity());
d69b2b
+                    slapi_search_get_entry(&entry_pb, bind_sdn, NULL, &test_e,
d69b2b
+                                           pam_passthruauth_get_plugin_identity());
d69b2b
 
d69b2b
                     /* If the entry doesn't exist, just fall through to the main server code */
d69b2b
                     if (test_e) {
d69b2b
                         /* Evaluate the filter. */
d69b2b
                         if (LDAP_SUCCESS == slapi_filter_test_simple(test_e, cfg->slapi_filter)) {
d69b2b
                             /* This is a match. */
d69b2b
-                            slapi_entry_free(test_e);
d69b2b
+                            slapi_search_get_entry_done(&entry_pb);
d69b2b
                             goto done;
d69b2b
                         }
d69b2b
-
d69b2b
-                        slapi_entry_free(test_e);
d69b2b
+                        slapi_search_get_entry_done(&entry_pb);
d69b2b
                     }
d69b2b
                 } else {
d69b2b
                     /* There is no filter to check, so this is a match. */
d69b2b
diff --git a/ldap/servers/plugins/pam_passthru/pam_ptimpl.c b/ldap/servers/plugins/pam_passthru/pam_ptimpl.c
d69b2b
index 7f5fb02c4..5b43f8d1f 100644
d69b2b
--- a/ldap/servers/plugins/pam_passthru/pam_ptimpl.c
d69b2b
+++ b/ldap/servers/plugins/pam_passthru/pam_ptimpl.c
d69b2b
@@ -81,11 +81,12 @@ derive_from_bind_dn(Slapi_PBlock *pb __attribute__((unused)), const Slapi_DN *bi
d69b2b
 static char *
d69b2b
 derive_from_bind_entry(Slapi_PBlock *pb, const Slapi_DN *bindsdn, MyStrBuf *pam_id, char *map_ident_attr, int *locked)
d69b2b
 {
d69b2b
+	Slapi_PBlock *entry_pb = NULL;
d69b2b
     Slapi_Entry *entry = NULL;
d69b2b
     char *attrs[] = {NULL, NULL};
d69b2b
     attrs[0] = map_ident_attr;
d69b2b
-    int rc = slapi_search_internal_get_entry((Slapi_DN *)bindsdn, attrs, &entry,
d69b2b
-                                             pam_passthruauth_get_plugin_identity());
d69b2b
+    int32_t rc = slapi_search_get_entry(&entry_pb, (Slapi_DN *)bindsdn, attrs, &entry,
d69b2b
+                                        pam_passthruauth_get_plugin_identity());
d69b2b
 
d69b2b
     if (rc != LDAP_SUCCESS) {
d69b2b
         slapi_log_err(SLAPI_LOG_ERR, PAM_PASSTHRU_PLUGIN_SUBSYSTEM,
d69b2b
@@ -108,7 +109,7 @@ derive_from_bind_entry(Slapi_PBlock *pb, const Slapi_DN *bindsdn, MyStrBuf *pam_
d69b2b
         init_my_str_buf(pam_id, val);
d69b2b
     }
d69b2b
 
d69b2b
-    slapi_entry_free(entry);
d69b2b
+    slapi_search_get_entry_done(&entry_pb);
d69b2b
 
d69b2b
     return pam_id->str;
d69b2b
 }
d69b2b
diff --git a/ldap/servers/plugins/pam_passthru/pam_ptpreop.c b/ldap/servers/plugins/pam_passthru/pam_ptpreop.c
d69b2b
index 3d0067531..5bca823ff 100644
d69b2b
--- a/ldap/servers/plugins/pam_passthru/pam_ptpreop.c
d69b2b
+++ b/ldap/servers/plugins/pam_passthru/pam_ptpreop.c
d69b2b
@@ -526,6 +526,7 @@ done:
d69b2b
 static int
d69b2b
 pam_passthru_preop(Slapi_PBlock *pb, int modtype)
d69b2b
 {
d69b2b
+	Slapi_PBlock *entry_pb = NULL;
d69b2b
     Slapi_DN *sdn = NULL;
d69b2b
     Slapi_Entry *e = NULL;
d69b2b
     LDAPMod **mods;
d69b2b
@@ -555,8 +556,8 @@ pam_passthru_preop(Slapi_PBlock *pb, int modtype)
d69b2b
         case LDAP_CHANGETYPE_MODIFY:
d69b2b
             /* Fetch the entry being modified so we can
d69b2b
              * create the resulting entry for validation. */
d69b2b
-            slapi_search_internal_get_entry(sdn, 0, &e,
d69b2b
-                                            pam_passthruauth_get_plugin_identity());
d69b2b
+            slapi_search_get_entry(&entry_pb, sdn, 0, &e,
d69b2b
+                                   pam_passthruauth_get_plugin_identity());
d69b2b
 
d69b2b
             /* If the entry doesn't exist, just bail and
d69b2b
              * let the server handle it. */
d69b2b
@@ -576,9 +577,6 @@ pam_passthru_preop(Slapi_PBlock *pb, int modtype)
d69b2b
                     /* Don't bail here, as we need to free the entry. */
d69b2b
                 }
d69b2b
             }
d69b2b
-
d69b2b
-            /* Free the entry. */
d69b2b
-            slapi_entry_free(e);
d69b2b
             break;
d69b2b
         case LDAP_CHANGETYPE_DELETE:
d69b2b
         case LDAP_CHANGETYPE_MODDN:
d69b2b
@@ -591,6 +589,7 @@ pam_passthru_preop(Slapi_PBlock *pb, int modtype)
d69b2b
     }
d69b2b
 
d69b2b
 bail:
d69b2b
+    slapi_search_get_entry_done(&entry_pb);
d69b2b
     /* If we are refusing the operation, return the result to the client. */
d69b2b
     if (ret) {
d69b2b
         slapi_send_ldap_result(pb, ret, NULL, returntext, 0, NULL);
d69b2b
diff --git a/ldap/servers/plugins/replication/repl5_tot_protocol.c b/ldap/servers/plugins/replication/repl5_tot_protocol.c
d69b2b
index 3b65d6b20..a25839f21 100644
d69b2b
--- a/ldap/servers/plugins/replication/repl5_tot_protocol.c
d69b2b
+++ b/ldap/servers/plugins/replication/repl5_tot_protocol.c
d69b2b
@@ -469,7 +469,8 @@ retry:
d69b2b
          */
d69b2b
         /* Get suffix */
d69b2b
         Slapi_Entry *suffix = NULL;
d69b2b
-        rc = slapi_search_internal_get_entry(area_sdn, NULL, &suffix, repl_get_plugin_identity(PLUGIN_MULTIMASTER_REPLICATION));
d69b2b
+        Slapi_PBlock *suffix_pb = NULL;
d69b2b
+        rc = slapi_search_get_entry(&suffix_pb, area_sdn, NULL, &suffix, repl_get_plugin_identity(PLUGIN_MULTIMASTER_REPLICATION));
d69b2b
         if (rc) {
d69b2b
             slapi_log_err(SLAPI_LOG_ERR, repl_plugin_name, "repl5_tot_run -  Unable to "
d69b2b
                                                            "get the suffix entry \"%s\".\n",
d69b2b
@@ -517,7 +518,7 @@ retry:
d69b2b
                                      LDAP_SCOPE_SUBTREE, "(parentid>=1)", NULL, 0, ctrls, NULL,
d69b2b
                                      repl_get_plugin_identity(PLUGIN_MULTIMASTER_REPLICATION), OP_FLAG_BULK_IMPORT);
d69b2b
         cb_data.num_entries = 0UL;
d69b2b
-        slapi_entry_free(suffix);
d69b2b
+        slapi_search_get_entry_done(&suffix_pb);
d69b2b
     } else {
d69b2b
         /* Original total update */
d69b2b
         /* we need to provide managedsait control so that referral entries can
d69b2b
diff --git a/ldap/servers/plugins/uiduniq/uid.c b/ldap/servers/plugins/uiduniq/uid.c
d69b2b
index d7ccf0e07..e69012204 100644
d69b2b
--- a/ldap/servers/plugins/uiduniq/uid.c
d69b2b
+++ b/ldap/servers/plugins/uiduniq/uid.c
d69b2b
@@ -1254,6 +1254,7 @@ preop_modify(Slapi_PBlock *pb)
d69b2b
 static int
d69b2b
 preop_modrdn(Slapi_PBlock *pb)
d69b2b
 {
d69b2b
+    Slapi_PBlock *entry_pb = NULL;
d69b2b
     int result = LDAP_SUCCESS;
d69b2b
     Slapi_Entry *e = NULL;
d69b2b
     Slapi_Value *sv_requiredObjectClass = NULL;
d69b2b
@@ -1351,7 +1352,7 @@ preop_modrdn(Slapi_PBlock *pb)
d69b2b
 
d69b2b
     /* Get the entry that is being renamed so we can make a dummy copy
d69b2b
      * of what it will look like after the rename. */
d69b2b
-    err = slapi_search_internal_get_entry(sdn, NULL, &e, plugin_identity);
d69b2b
+    err = slapi_search_get_entry(&entry_pb, sdn, NULL, &e, plugin_identity);
d69b2b
     if (err != LDAP_SUCCESS) {
d69b2b
         result = uid_op_error(35);
d69b2b
         /* We want to return a no such object error if the target doesn't exist. */
d69b2b
@@ -1371,24 +1372,24 @@ preop_modrdn(Slapi_PBlock *pb)
d69b2b
 
d69b2b
 
d69b2b
     /*
d69b2b
-         * Check if it has the required object class
d69b2b
-         */
d69b2b
+     * Check if it has the required object class
d69b2b
+     */
d69b2b
     if (requiredObjectClass &&
d69b2b
         !slapi_entry_attr_has_syntax_value(e, SLAPI_ATTR_OBJECTCLASS, sv_requiredObjectClass)) {
d69b2b
         break;
d69b2b
     }
d69b2b
 
d69b2b
     /*
d69b2b
-         * Find any unique attribute data in the new RDN
d69b2b
-         */
d69b2b
+     * Find any unique attribute data in the new RDN
d69b2b
+     */
d69b2b
     for (i = 0; attrNames && attrNames[i]; i++) {
d69b2b
         err = slapi_entry_attr_find(e, attrNames[i], &attr);
d69b2b
         if (!err) {
d69b2b
             /*
d69b2b
-                 * Passed all the requirements - this is an operation we
d69b2b
-                 * need to enforce uniqueness on. Now find all parent entries
d69b2b
-                 * with the marker object class, and do a search for each one.
d69b2b
-                 */
d69b2b
+             * Passed all the requirements - this is an operation we
d69b2b
+             * need to enforce uniqueness on. Now find all parent entries
d69b2b
+             * with the marker object class, and do a search for each one.
d69b2b
+             */
d69b2b
             if (NULL != markerObjectClass) {
d69b2b
                 /* Subtree defined by location of marker object class */
d69b2b
                 result = findSubtreeAndSearch(slapi_entry_get_sdn(e), attrNames, attr, NULL,
d69b2b
@@ -1407,8 +1408,8 @@ preop_modrdn(Slapi_PBlock *pb)
d69b2b
     END
d69b2b
         /* Clean-up */
d69b2b
         slapi_value_free(&sv_requiredObjectClass);
d69b2b
-    if (e)
d69b2b
-        slapi_entry_free(e);
d69b2b
+
d69b2b
+    slapi_search_get_entry_done(&entry_pb);
d69b2b
 
d69b2b
     if (result) {
d69b2b
         slapi_log_err(SLAPI_LOG_PLUGIN, plugin_name,
d69b2b
diff --git a/ldap/servers/slapd/daemon.c b/ldap/servers/slapd/daemon.c
d69b2b
index 65f23363a..a70f40316 100644
d69b2b
--- a/ldap/servers/slapd/daemon.c
d69b2b
+++ b/ldap/servers/slapd/daemon.c
d69b2b
@@ -1916,18 +1916,13 @@ slapd_bind_local_user(Connection *conn)
d69b2b
             char *root_dn = config_get_ldapi_root_dn();
d69b2b
 
d69b2b
             if (root_dn) {
d69b2b
+                Slapi_PBlock *entry_pb = NULL;
d69b2b
                 Slapi_DN *edn = slapi_sdn_new_dn_byref(
d69b2b
                     slapi_dn_normalize(root_dn));
d69b2b
                 Slapi_Entry *e = 0;
d69b2b
 
d69b2b
                 /* root might be locked too! :) */
d69b2b
-                ret = slapi_search_internal_get_entry(
d69b2b
-                    edn, 0,
d69b2b
-                    &e,
d69b2b
-                    (void *)plugin_get_default_component_id()
d69b2b
-
d69b2b
-                        );
d69b2b
-
d69b2b
+                ret = slapi_search_get_entry(&entry_pb, edn, 0, &e, (void *)plugin_get_default_component_id());
d69b2b
                 if (0 == ret && e) {
d69b2b
                     ret = slapi_check_account_lock(
d69b2b
                         0, /* pb not req */
d69b2b
@@ -1955,7 +1950,7 @@ slapd_bind_local_user(Connection *conn)
d69b2b
             root_map_free:
d69b2b
                 /* root_dn consumed by bind creds set */
d69b2b
                 slapi_sdn_free(&edn;;
d69b2b
-                slapi_entry_free(e);
d69b2b
+                slapi_search_get_entry_done(&entry_pb);
d69b2b
                 ret = 0;
d69b2b
             }
d69b2b
         }
d69b2b
diff --git a/ldap/servers/slapd/modify.c b/ldap/servers/slapd/modify.c
d69b2b
index bbc0ab71a..259bedfff 100644
d69b2b
--- a/ldap/servers/slapd/modify.c
d69b2b
+++ b/ldap/servers/slapd/modify.c
d69b2b
@@ -592,6 +592,7 @@ modify_internal_pb(Slapi_PBlock *pb)
d69b2b
 static void
d69b2b
 op_shared_modify(Slapi_PBlock *pb, int pw_change, char *old_pw)
d69b2b
 {
d69b2b
+    Slapi_PBlock *entry_pb = NULL;
d69b2b
     Slapi_Backend *be = NULL;
d69b2b
     Slapi_Entry *pse;
d69b2b
     Slapi_Entry *referral;
d69b2b
@@ -723,7 +724,7 @@ op_shared_modify(Slapi_PBlock *pb, int pw_change, char *old_pw)
d69b2b
      * 2. If yes, then if the mods contain any passwdpolicy specific attributes.
d69b2b
      * 3. If yes, then it invokes corrosponding checking function.
d69b2b
      */
d69b2b
-    if (!repl_op && !internal_op && normdn && (e = get_entry(pb, normdn))) {
d69b2b
+    if (!repl_op && !internal_op && normdn && slapi_search_get_entry(&entry_pb, sdn, NULL, &e, NULL) == LDAP_SUCCESS) {
d69b2b
         Slapi_Value target;
d69b2b
         slapi_value_init(&target);
d69b2b
         slapi_value_set_string(&target, "passwordpolicy");
d69b2b
@@ -1072,7 +1073,7 @@ free_and_return : {
d69b2b
     slapi_entry_free(epre);
d69b2b
     slapi_entry_free(epost);
d69b2b
 }
d69b2b
-    slapi_entry_free(e);
d69b2b
+    slapi_search_get_entry_done(&entry_pb);
d69b2b
 
d69b2b
     if (be)
d69b2b
         slapi_be_Unlock(be);
d69b2b
@@ -1202,12 +1203,13 @@ op_shared_allow_pw_change(Slapi_PBlock *pb, LDAPMod *mod, char **old_pw, Slapi_M
d69b2b
     if (!internal_op) {
d69b2b
         /* slapi_acl_check_mods needs an array of LDAPMods, but
d69b2b
          * we're really only interested in the one password mod. */
d69b2b
+        Slapi_PBlock *entry_pb = NULL;
d69b2b
         LDAPMod *mods[2];
d69b2b
         mods[0] = mod;
d69b2b
         mods[1] = NULL;
d69b2b
 
d69b2b
         /* We need to actually fetch the target here to use for ACI checking. */
d69b2b
-        slapi_search_internal_get_entry(&sdn, NULL, &e, (void *)plugin_get_default_component_id());
d69b2b
+        slapi_search_get_entry(&entry_pb, &sdn, NULL, &e, NULL);
d69b2b
 
d69b2b
         /* Create a bogus entry with just the target dn if we were unable to
d69b2b
          * find the actual entry.  This will only be used for checking the ACIs. */
d69b2b
@@ -1238,9 +1240,12 @@ op_shared_allow_pw_change(Slapi_PBlock *pb, LDAPMod *mod, char **old_pw, Slapi_M
d69b2b
             }
d69b2b
             send_ldap_result(pb, res, NULL, errtxt, 0, NULL);
d69b2b
             slapi_ch_free_string(&errtxt);
d69b2b
+            slapi_search_get_entry_done(&entry_pb);
d69b2b
             rc = -1;
d69b2b
             goto done;
d69b2b
         }
d69b2b
+        /* done with slapi entry e */
d69b2b
+        slapi_search_get_entry_done(&entry_pb);
d69b2b
 
d69b2b
         /*
d69b2b
          * If this mod is being performed by a password administrator/rootDN,
d69b2b
@@ -1353,7 +1358,6 @@ op_shared_allow_pw_change(Slapi_PBlock *pb, LDAPMod *mod, char **old_pw, Slapi_M
d69b2b
     valuearray_free(&values);
d69b2b
 
d69b2b
 done:
d69b2b
-    slapi_entry_free(e);
d69b2b
     slapi_sdn_done(&sdn;;
d69b2b
     slapi_ch_free_string(&proxydn);
d69b2b
     slapi_ch_free_string(&proxystr);
d69b2b
diff --git a/ldap/servers/slapd/plugin_internal_op.c b/ldap/servers/slapd/plugin_internal_op.c
d69b2b
index 9da266b61..a140e7988 100644
d69b2b
--- a/ldap/servers/slapd/plugin_internal_op.c
d69b2b
+++ b/ldap/servers/slapd/plugin_internal_op.c
d69b2b
@@ -882,3 +882,51 @@ slapi_search_internal_get_entry(Slapi_DN *dn, char **attrs, Slapi_Entry **ret_en
d69b2b
     int_search_pb = NULL;
d69b2b
     return rc;
d69b2b
 }
d69b2b
+
d69b2b
+int32_t
d69b2b
+slapi_search_get_entry(Slapi_PBlock **pb, Slapi_DN *dn, char **attrs, Slapi_Entry **ret_entry, void *component_identity)
d69b2b
+{
d69b2b
+    Slapi_Entry **entries = NULL;
d69b2b
+    int32_t rc = 0;
d69b2b
+    void *component = component_identity;
d69b2b
+
d69b2b
+    if (ret_entry) {
d69b2b
+        *ret_entry = NULL;
d69b2b
+    }
d69b2b
+
d69b2b
+    if (component == NULL) {
d69b2b
+        component = (void *)plugin_get_default_component_id();
d69b2b
+    }
d69b2b
+
d69b2b
+    if (*pb == NULL) {
d69b2b
+        *pb = slapi_pblock_new();
d69b2b
+    }
d69b2b
+    slapi_search_internal_set_pb(*pb, slapi_sdn_get_dn(dn), LDAP_SCOPE_BASE,
d69b2b
+        "(|(objectclass=*)(objectclass=ldapsubentry))",
d69b2b
+        attrs, 0, NULL, NULL, component, 0 );
d69b2b
+    slapi_search_internal_pb(*pb);
d69b2b
+    slapi_pblock_get(*pb, SLAPI_PLUGIN_INTOP_RESULT, &rc);
d69b2b
+    if (LDAP_SUCCESS == rc) {
d69b2b
+        slapi_pblock_get(*pb, SLAPI_PLUGIN_INTOP_SEARCH_ENTRIES, &entries);
d69b2b
+        if (NULL != entries && NULL != entries[0]) {
d69b2b
+            /* Only need to dup the entry if the caller passed ret_entry in. */
d69b2b
+            if (ret_entry) {
d69b2b
+                *ret_entry = entries[0];
d69b2b
+            }
d69b2b
+        } else {
d69b2b
+            rc = LDAP_NO_SUCH_OBJECT;
d69b2b
+        }
d69b2b
+    }
d69b2b
+
d69b2b
+    return rc;
d69b2b
+}
d69b2b
+
d69b2b
+void
d69b2b
+slapi_search_get_entry_done(Slapi_PBlock **pb)
d69b2b
+{
d69b2b
+    if (pb && *pb) {
d69b2b
+        slapi_free_search_results_internal(*pb);
d69b2b
+        slapi_pblock_destroy(*pb);
d69b2b
+        *pb = NULL;
d69b2b
+    }
d69b2b
+}
d69b2b
diff --git a/ldap/servers/slapd/resourcelimit.c b/ldap/servers/slapd/resourcelimit.c
d69b2b
index 705344c84..9c2619716 100644
d69b2b
--- a/ldap/servers/slapd/resourcelimit.c
d69b2b
+++ b/ldap/servers/slapd/resourcelimit.c
d69b2b
@@ -305,22 +305,17 @@ reslimit_get_ext(Slapi_Connection *conn, const char *logname, SLAPIResLimitConnD
d69b2b
 int
d69b2b
 reslimit_update_from_dn(Slapi_Connection *conn, Slapi_DN *dn)
d69b2b
 {
d69b2b
-    Slapi_Entry *e;
d69b2b
+    Slapi_PBlock *pb = NULL;
d69b2b
+    Slapi_Entry *e = NULL;
d69b2b
     int rc;
d69b2b
 
d69b2b
-    e = NULL;
d69b2b
     if (dn != NULL) {
d69b2b
-
d69b2b
         char **attrs = reslimit_get_registered_attributes();
d69b2b
-        (void)slapi_search_internal_get_entry(dn, attrs, &e, reslimit_componentid);
d69b2b
+        slapi_search_get_entry(&pb, dn, attrs, &e, reslimit_componentid);
d69b2b
         charray_free(attrs);
d69b2b
     }
d69b2b
-
d69b2b
     rc = reslimit_update_from_entry(conn, e);
d69b2b
-
d69b2b
-    if (NULL != e) {
d69b2b
-        slapi_entry_free(e);
d69b2b
-    }
d69b2b
+    slapi_search_get_entry_done(&pb;;
d69b2b
 
d69b2b
     return (rc);
d69b2b
 }
d69b2b
diff --git a/ldap/servers/slapd/schema.c b/ldap/servers/slapd/schema.c
d69b2b
index d44b03b0e..bf7e59f75 100644
d69b2b
--- a/ldap/servers/slapd/schema.c
d69b2b
+++ b/ldap/servers/slapd/schema.c
d69b2b
@@ -341,6 +341,7 @@ schema_policy_add_action(Slapi_Entry *entry, char *attrName, schema_item_t **lis
d69b2b
 static void
d69b2b
 schema_load_repl_policy(const char *dn, repl_schema_policy_t *replica)
d69b2b
 {
d69b2b
+    Slapi_PBlock *pb = NULL;
d69b2b
     Slapi_DN sdn;
d69b2b
     Slapi_Entry *entry = NULL;
d69b2b
     schema_item_t *schema_item, *next;
d69b2b
@@ -369,8 +370,7 @@ schema_load_repl_policy(const char *dn, repl_schema_policy_t *replica)
d69b2b
 
d69b2b
     /* Load the replication policy of the schema  */
d69b2b
     slapi_sdn_init_dn_byref(&sdn, dn);
d69b2b
-    if (slapi_search_internal_get_entry(&sdn, NULL, &entry, plugin_get_default_component_id()) == LDAP_SUCCESS) {
d69b2b
-
d69b2b
+    if (slapi_search_get_entry(&pb, &sdn, NULL, &entry, plugin_get_default_component_id()) == LDAP_SUCCESS) {
d69b2b
         /* fill the policies (accept/reject) regarding objectclass */
d69b2b
         schema_policy_add_action(entry, ATTR_SCHEMA_UPDATE_OBJECTCLASS_ACCEPT, &replica->objectclasses);
d69b2b
         schema_policy_add_action(entry, ATTR_SCHEMA_UPDATE_OBJECTCLASS_REJECT, &replica->objectclasses);
d69b2b
@@ -378,9 +378,8 @@ schema_load_repl_policy(const char *dn, repl_schema_policy_t *replica)
d69b2b
         /* fill the policies (accept/reject) regarding attribute */
d69b2b
         schema_policy_add_action(entry, ATTR_SCHEMA_UPDATE_ATTRIBUTE_ACCEPT, &replica->attributes);
d69b2b
         schema_policy_add_action(entry, ATTR_SCHEMA_UPDATE_ATTRIBUTE_REJECT, &replica->attributes);
d69b2b
-
d69b2b
-        slapi_entry_free(entry);
d69b2b
     }
d69b2b
+    slapi_search_get_entry_done(&pb;;
d69b2b
     slapi_sdn_done(&sdn;;
d69b2b
 }
d69b2b
 
d69b2b
diff --git a/ldap/servers/slapd/slapi-plugin.h b/ldap/servers/slapd/slapi-plugin.h
d69b2b
index 0e3857068..be1e52e4d 100644
d69b2b
--- a/ldap/servers/slapd/slapi-plugin.h
d69b2b
+++ b/ldap/servers/slapd/slapi-plugin.h
d69b2b
@@ -5972,7 +5972,7 @@ void slapi_seq_internal_set_pb(Slapi_PBlock *pb, char *ibase, int type, char *at
d69b2b
 
d69b2b
 /*
d69b2b
  * slapi_search_internal_get_entry() finds an entry given a dn.  It returns
d69b2b
- * an LDAP error code (LDAP_SUCCESS if all goes well).
d69b2b
+ * an LDAP error code (LDAP_SUCCESS if all goes well).  Caller must free ret_entry
d69b2b
  */
d69b2b
 int slapi_search_internal_get_entry(Slapi_DN *dn, char **attrlist, Slapi_Entry **ret_entry, void *caller_identity);
d69b2b
 
d69b2b
@@ -8296,6 +8296,27 @@ uint64_t slapi_atomic_decr_64(uint64_t *ptr, int memorder);
d69b2b
 /* helper function */
d69b2b
 const char * slapi_fetch_attr(Slapi_Entry *e, const char *attrname, char *default_val);
d69b2b
 
d69b2b
+/**
d69b2b
+ * Get a Slapi_Entry via an internal search.  The caller then needs to call
d69b2b
+ * slapi_get_entry_done() to free any resources allocated to get the entry
d69b2b
+ *
d69b2b
+ * \param pb - slapi_pblock pointer (the function will allocate if necessary)
d69b2b
+ * \param dn - Slapi_DN of the entry to retrieve
d69b2b
+ * \param attrs - char list of attributes to get
d69b2b
+ * \param ret_entry - pointer to a Slapi_entry wer the returned entry is stored
d69b2b
+ * \param component_identity - plugin component
d69b2b
+ *
d69b2b
+ * \return - ldap result code
d69b2b
+ */
d69b2b
+int32_t slapi_search_get_entry(Slapi_PBlock **pb, Slapi_DN *dn, char **attrs, Slapi_Entry **ret_entry, void *component_identity);
d69b2b
+
d69b2b
+/**
d69b2b
+ * Free the resources allocated by slapi_search_get_entry()
d69b2b
+ *
d69b2b
+ * \param pb - slapi_pblock pointer
d69b2b
+ */
d69b2b
+void slapi_search_get_entry_done(Slapi_PBlock **pb);
d69b2b
+
d69b2b
 #ifdef __cplusplus
d69b2b
 }
d69b2b
 #endif
d69b2b
-- 
d69b2b
2.26.2
d69b2b