Blame SOURCES/0004-Ticket-50431-Fix-covscan-warnings.patch

232633
From 3d8e1c62134fe5e98edef167ce88f473adda722a Mon Sep 17 00:00:00 2001
232633
From: Mark Reynolds <mreynolds@redhat.com>
232633
Date: Wed, 5 Jun 2019 14:09:52 -0400
232633
Subject: [PATCH] Ticket 50431 - Fix covscan warnings
232633
232633
Description:  Most coverity errors happen when something fails.
232633
232633
https://pagure.io/389-ds-base/issue/50431
232633
232633
Reviewed by: firstyear & spichugi(Thanks!)
232633
---
232633
 autogen.sh                                    |  8 ++-
232633
 ldap/servers/plugins/acl/acl.c                | 15 ++---
232633
 ldap/servers/plugins/acl/acleffectiverights.c | 12 ++--
232633
 ldap/servers/plugins/acl/acllist.c            |  4 +-
232633
 .../plugins/linkedattrs/linked_attrs.c        |  4 +-
232633
 .../plugins/memberof/memberof_config.c        | 12 +++-
232633
 .../plugins/posix-winsync/posix-winsync.c     |  2 +-
232633
 ldap/servers/plugins/replication/cl5_api.c    |  1 +
232633
 .../plugins/replication/repl5_replica.c       |  2 +-
232633
 .../replication/repl5_replica_config.c        |  8 ++-
232633
 ldap/servers/plugins/replication/urp.c        |  1 +
232633
 ldap/servers/plugins/roles/roles_cache.c      |  2 +
232633
 ldap/servers/plugins/views/views.c            | 16 ++++--
232633
 ldap/servers/slapd/agtmmap.c                  |  2 +-
232633
 ldap/servers/slapd/back-ldbm/dblayer.c        | 55 ++++++++++--------
232633
 ldap/servers/slapd/back-ldbm/index.c          |  9 +--
232633
 ldap/servers/slapd/back-ldbm/ldbm_add.c       |  3 +-
232633
 .../slapd/back-ldbm/ldbm_attrcrypt_config.c   |  4 +-
232633
 ldap/servers/slapd/back-ldbm/ldbm_delete.c    |  3 +-
232633
 ldap/servers/slapd/back-ldbm/ldif2ldbm.c      |  4 +-
232633
 ldap/servers/slapd/back-ldbm/vlv_srch.c       |  3 +-
232633
 ldap/servers/slapd/connection.c               |  1 +
232633
 ldap/servers/slapd/dse.c                      |  7 ++-
232633
 ldap/servers/slapd/entrywsi.c                 | 57 ++++++++++---------
232633
 ldap/servers/slapd/main.c                     |  9 +--
232633
 ldap/servers/slapd/mapping_tree.c             | 46 +++++++--------
232633
 ldap/servers/slapd/modify.c                   |  6 +-
232633
 ldap/servers/slapd/opshared.c                 |  3 +-
232633
 ldap/servers/slapd/plugin_internal_op.c       |  3 +-
232633
 ldap/servers/slapd/plugin_syntax.c            |  4 +-
232633
 ldap/servers/slapd/rdn.c                      |  5 +-
232633
 ldap/servers/slapd/sasl_map.c                 |  4 +-
232633
 ldap/servers/slapd/schema.c                   |  6 +-
232633
 ldap/servers/slapd/search.c                   |  7 ++-
232633
 ldap/servers/slapd/tools/dbscan.c             |  9 ++-
232633
 ldap/servers/slapd/tools/ldclt/ldapfct.c      |  8 +--
232633
 ldap/servers/slapd/tools/ldclt/ldclt.c        |  2 +-
232633
 ldap/servers/slapd/tools/ldif.c               | 10 +++-
232633
 ldap/servers/slapd/tools/mmldif.c             |  5 +-
232633
 ldap/servers/slapd/tools/pwenc.c              |  1 +
232633
 ldap/servers/slapd/tools/rsearch/infadd.c     |  2 +-
232633
 ldap/servers/slapd/tools/rsearch/rsearch.c    |  5 +-
232633
 lib/ldaputil/certmap.c                        | 15 ++---
232633
 lib/libaccess/usrcache.cpp                    |  6 +-
232633
 .../389-console/src/lib/database/chaining.jsx |  2 +-
232633
 .../389-console/src/lib/database/suffix.jsx   |  4 +-
232633
 src/cockpit/389-console/src/replication.js    |  2 +-
232633
 src/lib389/lib389/agreement.py                |  1 +
232633
 src/lib389/lib389/backend.py                  |  8 ++-
232633
 src/lib389/lib389/cli_conf/backend.py         |  2 +-
232633
 50 files changed, 229 insertions(+), 181 deletions(-)
232633
232633
diff --git a/autogen.sh b/autogen.sh
232633
index 8bb628b25..06a5facd1 100755
232633
--- a/autogen.sh
232633
+++ b/autogen.sh
232633
@@ -35,12 +35,16 @@ checkvers() {
232633
     vers="$1"; shift
232633
     needmaj="$1"; shift
232633
     needmin="$1"; shift
232633
-    needrev="$1"; shift
232633
+    if [ "$#" != "0" ]; then
232633
+        needrev="$1"; shift
232633
+    fi
232633
     verslist=`echo $vers | tr '.' ' '`
232633
     set $verslist
232633
     maj=$1; shift
232633
     min=$1; shift
232633
-    rev=$1; shift
232633
+    if [ "$#" != "0" ]; then
232633
+        rev=$1; shift
232633
+    fi
232633
     if [ "$maj" -gt "$needmaj" ] ; then return 0; fi
232633
     if [ "$maj" -lt "$needmaj" ] ; then return 1; fi
232633
     # if we got here, maj == needmaj
232633
diff --git a/ldap/servers/plugins/acl/acl.c b/ldap/servers/plugins/acl/acl.c
232633
index 6d105f4fa..5680de669 100644
232633
--- a/ldap/servers/plugins/acl/acl.c
232633
+++ b/ldap/servers/plugins/acl/acl.c
232633
@@ -644,7 +644,8 @@ cleanup_and_ret:
232633
     if (aclpb)
232633
         aclpb->aclpb_curr_attrEval = NULL;
232633
 
232633
-    print_access_control_summary("main", ret_val, clientDn, aclpb, right,
232633
+    print_access_control_summary("main", ret_val, clientDn, aclpb,
232633
+                                 (right ? right : "NULL"),
232633
                                  (attr ? attr : "NULL"), n_edn,
232633
                                  &decision_reason);
232633
     TNF_PROBE_0_DEBUG(acl_cleanup_end, "ACL", "");
232633
@@ -2590,12 +2591,9 @@ acl__resource_match_aci(Acl_PBlock *aclpb, aci_t *aci, int skip_attrEval, int *a
232633
          * that applies to the current attribute.
232633
          * Then the (attribute,value) pair being added/deleted better
232633
          * match that filter.
232633
-         *
232633
-         *
232633
          */
232633
-
232633
         Targetattrfilter **attrFilterArray = NULL;
232633
-        Targetattrfilter *attrFilter;
232633
+        Targetattrfilter *attrFilter = NULL;
232633
         int found = 0;
232633
 
232633
         if ((aclpb->aclpb_access & ACLPB_SLAPI_ACL_WRITE_ADD) &&
232633
@@ -2606,15 +2604,13 @@ acl__resource_match_aci(Acl_PBlock *aclpb, aci_t *aci, int skip_attrEval, int *a
232633
             attrFilterArray = aci->targetAttrDelFilters;
232633
         }
232633
 
232633
-
232633
         /*
232633
          * Scan this filter list for an applicable filter.
232633
          */
232633
-
232633
         found = 0;
232633
         num_attrs = 0;
232633
 
232633
-        while (attrFilterArray[num_attrs] && !found) {
232633
+        while (attrFilterArray && attrFilterArray[num_attrs] && !found) {
232633
             attrFilter = attrFilterArray[num_attrs];
232633
 
232633
             /* If this filter applies to the attribute, stop. */
232633
@@ -2630,8 +2626,7 @@ acl__resource_match_aci(Acl_PBlock *aclpb, aci_t *aci, int skip_attrEval, int *a
232633
          * Here, if found an applicable filter, then apply the filter to the
232633
          * (attr,val) pair.
232633
          * Otherwise, ignore the targetattrfilters.
232633
-        */
232633
-
232633
+         */
232633
         if (found) {
232633
 
232633
             if (acl__make_filter_test_entry(&aclpb->aclpb_filter_test_entry,
232633
diff --git a/ldap/servers/plugins/acl/acleffectiverights.c b/ldap/servers/plugins/acl/acleffectiverights.c
232633
index 8a0cb9122..5dd46a064 100644
232633
--- a/ldap/servers/plugins/acl/acleffectiverights.c
232633
+++ b/ldap/servers/plugins/acl/acleffectiverights.c
232633
@@ -869,14 +869,14 @@ _ger_generate_template_entry(
232633
         if (dntype) {
232633
             siz += strlen(dntype) + 30 + strlen(object) + strlen(dn);
232633
         } else {
232633
-            siz += strlen(attrs[0]) + 30 + strlen(object) + strlen(dn);
232633
+            siz += strlen(attrs[0] ? attrs[0] : "") + 30 + strlen(object) + strlen(dn);
232633
         }
232633
     } else {
232633
         /* dn: <attr>=<template_name>\n\0 */
232633
         if (dntype) {
232633
             siz += strlen(dntype) + 30 + strlen(object);
232633
         } else {
232633
-            siz += strlen(attrs[0]) + 30 + strlen(object);
232633
+            siz += strlen(attrs[0] ? attrs[0] : "") + 30 + strlen(object);
232633
         }
232633
     }
232633
     templateentry = (char *)slapi_ch_malloc(siz);
232633
@@ -1030,7 +1030,9 @@ bailout:
232633
      * slapi_pblock_set() will free any previous data, and
232633
      * pblock_done() will free SLAPI_PB_RESULT_TEXT.
232633
      */
232633
-    slapi_pblock_set(pb, SLAPI_PB_RESULT_TEXT, gerstr);
232633
+    if (gerstr) {
232633
+        slapi_pblock_set(pb, SLAPI_PB_RESULT_TEXT, gerstr);
232633
+    }
232633
 
232633
     if (!iscritical) {
232633
         /*
232633
@@ -1040,7 +1042,7 @@ bailout:
232633
         rc = LDAP_SUCCESS;
232633
     }
232633
 
232633
-    slapi_ch_free((void **)&subjectndn);
232633
-    slapi_ch_free((void **)&gerstr);
232633
+    slapi_ch_free_string(&subjectndn);
232633
+    slapi_ch_free_string(&gerstr);
232633
     return rc;
232633
 }
232633
diff --git a/ldap/servers/plugins/acl/acllist.c b/ldap/servers/plugins/acl/acllist.c
232633
index 79786b723..e80c567c3 100644
232633
--- a/ldap/servers/plugins/acl/acllist.c
232633
+++ b/ldap/servers/plugins/acl/acllist.c
232633
@@ -255,7 +255,9 @@ __acllist_add_aci(aci_t *aci)
232633
                 t_aci = t_aci->aci_next;
232633
 
232633
             /* Now add the new one to the end of the list */
232633
-            t_aci->aci_next = aci;
232633
+            if (t_aci) {
232633
+                t_aci->aci_next = aci;
232633
+            }
232633
 
232633
             slapi_log_err(SLAPI_LOG_ACL, plugin_name, "__acllist_add_aci - Added the ACL:%s to existing container:[%d]%s\n",
232633
                           aci->aclName, head->acic_index, slapi_sdn_get_ndn(head->acic_sdn));
232633
diff --git a/ldap/servers/plugins/linkedattrs/linked_attrs.c b/ldap/servers/plugins/linkedattrs/linked_attrs.c
232633
index f6eee1957..4f9fb102b 100644
232633
--- a/ldap/servers/plugins/linkedattrs/linked_attrs.c
232633
+++ b/ldap/servers/plugins/linkedattrs/linked_attrs.c
232633
@@ -1256,7 +1256,9 @@ linked_attrs_del_backpointers(Slapi_PBlock *pb, char *linkdn, struct configEntry
232633
 
232633
         slapi_pblock_get(pb, SLAPI_ENTRY_PRE_OP, &pre_e);
232633
         slapi_entry_attr_find(pre_e, config->linktype, &pre_attr);
232633
-        slapi_attr_get_valueset(pre_attr, &vals);
232633
+        if (pre_attr) {
232633
+            slapi_attr_get_valueset(pre_attr, &vals);
232633
+        }
232633
     } else {
232633
         vals = slapi_valueset_new();
232633
         slapi_valueset_set_from_smod(vals, smod);
232633
diff --git a/ldap/servers/plugins/memberof/memberof_config.c b/ldap/servers/plugins/memberof/memberof_config.c
232633
index 89fd012e7..124217ee0 100644
232633
--- a/ldap/servers/plugins/memberof/memberof_config.c
232633
+++ b/ldap/servers/plugins/memberof/memberof_config.c
232633
@@ -550,13 +550,17 @@ memberof_apply_config(Slapi_PBlock *pb __attribute__((unused)),
232633
         }
232633
 
232633
         /* Build the new list */
232633
-        for (i = 0; theConfig.group_slapiattrs && theConfig.groupattrs && theConfig.groupattrs[i]; i++) {
232633
+        for (i = 0; theConfig.group_slapiattrs && theConfig.group_slapiattrs[i] &&
232633
+                    theConfig.groupattrs && theConfig.groupattrs[i]; i++)
232633
+        {
232633
             theConfig.group_slapiattrs[i] = slapi_attr_new();
232633
             slapi_attr_init(theConfig.group_slapiattrs[i], theConfig.groupattrs[i]);
232633
         }
232633
 
232633
         /* Terminate the list. */
232633
-        theConfig.group_slapiattrs[i] = NULL;
232633
+        if (theConfig.group_slapiattrs) {
232633
+            theConfig.group_slapiattrs[i] = NULL;
232633
+        }
232633
 
232633
         /* The filter is based off of the groupattr, so we update it here too. */
232633
         slapi_filter_free(theConfig.group_filter, 1);
232633
@@ -736,7 +740,9 @@ memberof_copy_config(MemberOfConfig *dest, MemberOfConfig *src)
232633
             }
232633
 
232633
             /* Terminate the array. */
232633
-            dest->group_slapiattrs[i] = NULL;
232633
+            if (dest->group_slapiattrs) {
232633
+                dest->group_slapiattrs[i] = NULL;
232633
+            }
232633
         }
232633
 
232633
         if (src->memberof_attr) {
232633
diff --git a/ldap/servers/plugins/posix-winsync/posix-winsync.c b/ldap/servers/plugins/posix-winsync/posix-winsync.c
232633
index 8e5ca4fff..c56e55f49 100644
232633
--- a/ldap/servers/plugins/posix-winsync/posix-winsync.c
232633
+++ b/ldap/servers/plugins/posix-winsync/posix-winsync.c
232633
@@ -1114,7 +1114,7 @@ posix_winsync_pre_ds_mod_group_cb(void *cbdata __attribute__((unused)),
232633
 
232633
         slapi_value_init_string(voc, "posixGroup");
232633
         slapi_entry_attr_find(ds_entry, "objectClass", &oc_attr);
232633
-        if (slapi_attr_value_find(oc_attr, slapi_value_get_berval(voc)) != 0) {
232633
+        if (oc_attr && slapi_attr_value_find(oc_attr, slapi_value_get_berval(voc)) != 0) {
232633
             Slapi_ValueSet *oc_vs = NULL;
232633
             Slapi_Value *oc_nv = slapi_value_new();
232633
 
232633
diff --git a/ldap/servers/plugins/replication/cl5_api.c b/ldap/servers/plugins/replication/cl5_api.c
232633
index c035db290..6b5b28b0b 100644
232633
--- a/ldap/servers/plugins/replication/cl5_api.c
232633
+++ b/ldap/servers/plugins/replication/cl5_api.c
232633
@@ -2749,6 +2749,7 @@ _cl5UpgradeMajor(char *fromVersion, char *toVersion)
232633
     if (rc != CL5_SUCCESS) {
232633
         slapi_log_err(SLAPI_LOG_ERR, repl_plugin_name_cl,
232633
                       "_cl5UpgradeMajor - Failed to open the db env\n");
232633
+        s_cl5Desc.dbOpenMode = backup;
232633
         return rc;
232633
     }
232633
     s_cl5Desc.dbOpenMode = backup;
232633
diff --git a/ldap/servers/plugins/replication/repl5_replica.c b/ldap/servers/plugins/replication/repl5_replica.c
232633
index b3d619862..6a5363e43 100644
232633
--- a/ldap/servers/plugins/replication/repl5_replica.c
232633
+++ b/ldap/servers/plugins/replication/repl5_replica.c
232633
@@ -2317,7 +2317,7 @@ replica_check_for_tasks(time_t when __attribute__((unused)), void *arg)
232633
                         "missing original task flag.  Aborting abort task!\n",
232633
                         clean_vals[i]);
232633
                 replica_delete_task_config(e, (char *)type_replicaAbortCleanRUV, orig_val);
232633
-                goto done;
232633
+                goto done2;
232633
             }
232633
 
232633
             if (!is_cleaned_rid(rid)) {
232633
diff --git a/ldap/servers/plugins/replication/repl5_replica_config.c b/ldap/servers/plugins/replication/repl5_replica_config.c
232633
index 02b645f41..7649aa14e 100644
232633
--- a/ldap/servers/plugins/replication/repl5_replica_config.c
232633
+++ b/ldap/servers/plugins/replication/repl5_replica_config.c
232633
@@ -223,6 +223,7 @@ replica_config_add(Slapi_PBlock *pb __attribute__((unused)),
232633
               }
232633
               slapi_log_err(SLAPI_LOG_ERR, repl_plugin_name, "replica_config_add - "MSG_NOREPLICANORMRDN);
232633
               slapi_rdn_free(&replicardn);
232633
+              slapi_ch_free_string(&replica_root);
232633
               *returncode = LDAP_UNWILLING_TO_PERFORM;
232633
               return SLAPI_DSE_CALLBACK_ERROR;
232633
           } else {
232633
@@ -232,6 +233,7 @@ replica_config_add(Slapi_PBlock *pb __attribute__((unused)),
232633
                  }
232633
                  slapi_log_err(SLAPI_LOG_ERR, repl_plugin_name,"replica_config_add - "MSG_CNREPLICA, nrdn, REPLICA_RDN);
232633
                  slapi_rdn_free(&replicardn);
232633
+                 slapi_ch_free_string(&replica_root);
232633
                  *returncode = LDAP_UNWILLING_TO_PERFORM;
232633
                  return SLAPI_DSE_CALLBACK_ERROR;
232633
              }
232633
@@ -242,6 +244,7 @@ replica_config_add(Slapi_PBlock *pb __attribute__((unused)),
232633
             strcpy(errortext, MSG_NOREPLICARDN);
232633
         }
232633
         slapi_log_err(SLAPI_LOG_ERR, repl_plugin_name, "replica_config_add - "MSG_NOREPLICARDN);
232633
+        slapi_ch_free_string(&replica_root);
232633
         *returncode = LDAP_UNWILLING_TO_PERFORM;
232633
         return SLAPI_DSE_CALLBACK_ERROR;
232633
     }
232633
@@ -287,7 +290,7 @@ done:
232633
 
232633
     PR_Unlock(s_configLock);
232633
     /* slapi_ch_free accepts NULL pointer */
232633
-    slapi_ch_free((void **)&replica_root);
232633
+    slapi_ch_free_string(&replica_root);
232633
 
232633
     if (*returncode != LDAP_SUCCESS) {
232633
         if (mtnode_ext->replica)
232633
@@ -2083,7 +2086,6 @@ check_replicas_are_done_cleaning(cleanruv_data *data)
232633
     while (not_all_cleaned && !is_task_aborted(data->rid) && !slapi_is_shutting_down()) {
232633
         agmt_obj = agmtlist_get_first_agreement_for_replica(data->replica);
232633
         if (agmt_obj == NULL) {
232633
-            not_all_cleaned = 0;
232633
             break;
232633
         }
232633
         while (agmt_obj && !slapi_is_shutting_down()) {
232633
@@ -2196,7 +2198,6 @@ check_replicas_are_done_aborting(cleanruv_data *data)
232633
     while (not_all_aborted && !slapi_is_shutting_down()) {
232633
         agmt_obj = agmtlist_get_first_agreement_for_replica(data->replica);
232633
         if (agmt_obj == NULL) {
232633
-            not_all_aborted = 0;
232633
             break;
232633
         }
232633
         while (agmt_obj && !slapi_is_shutting_down()) {
232633
@@ -2803,6 +2804,7 @@ delete_cleaned_rid_config(cleanruv_data *clean_data)
232633
                             cleanruv_log(clean_data->task, clean_data->rid, CLEANALLRUV_ID, SLAPI_LOG_ERR,
232633
                                     "delete_cleaned_rid_config - Failed to remove task data from (%s) error (%d), rid (%d)",
232633
                                     edn, rc, clean_data->rid);
232633
+                            slapi_ch_array_free(attr_val);
232633
                             goto bail;
232633
                         }
232633
                     }
232633
diff --git a/ldap/servers/plugins/replication/urp.c b/ldap/servers/plugins/replication/urp.c
232633
index 37fe77379..b134409e4 100644
232633
--- a/ldap/servers/plugins/replication/urp.c
232633
+++ b/ldap/servers/plugins/replication/urp.c
232633
@@ -1602,6 +1602,7 @@ urp_find_tombstone_for_glue (Slapi_PBlock *pb, char *sessionid, const Slapi_Entr
232633
     for (int i = 0; entries && (entries[i] != NULL); i++) {
232633
         char *tombstone_csn_value = slapi_entry_attr_get_charptr(entries[i], "nstombstonecsn");
232633
         if (tombstone_csn_value) {
232633
+            csn_free(&tombstone_csn);
232633
             tombstone_csn = csn_new_by_string(tombstone_csn_value);
232633
             slapi_ch_free_string(&tombstone_csn_value);
232633
             if( csn_compare(tombstone_csn, conflict_csn) > 0 ) {
232633
diff --git a/ldap/servers/plugins/roles/roles_cache.c b/ldap/servers/plugins/roles/roles_cache.c
232633
index 1e5865af8..4e3b0af54 100644
232633
--- a/ldap/servers/plugins/roles/roles_cache.c
232633
+++ b/ldap/servers/plugins/roles/roles_cache.c
232633
@@ -1276,6 +1276,8 @@ roles_cache_create_object_from_entry(Slapi_Entry *role_entry, role_object **resu
232633
 
232633
     if (rc == 0) {
232633
         *result = this_role;
232633
+    } else {
232633
+        slapi_ch_free((void **)&this_role);
232633
     }
232633
 
232633
     slapi_log_err(SLAPI_LOG_PLUGIN, ROLES_PLUGIN_SUBSYSTEM,
232633
diff --git a/ldap/servers/plugins/views/views.c b/ldap/servers/plugins/views/views.c
232633
index 6f784f599..5d8464761 100644
232633
--- a/ldap/servers/plugins/views/views.c
232633
+++ b/ldap/servers/plugins/views/views.c
232633
@@ -783,10 +783,12 @@ views_cache_create_applied_filter(viewEntry *pView)
232633
                           "views_cache_create_applied_filter - View filter [%s] in entry [%s] is not valid\n",
232633
                           buf, current->pDn);
232633
         }
232633
-        if (pBuiltFilter && pCurrentFilter)
232633
+        if (pBuiltFilter && pCurrentFilter) {
232633
             pBuiltFilter = slapi_filter_join_ex(LDAP_FILTER_AND, pBuiltFilter, pCurrentFilter, 0);
232633
-        else
232633
+        } else {
232633
+            slapi_filter_free(pBuiltFilter, 1);
232633
             pBuiltFilter = pCurrentFilter;
232633
+        }
232633
 
232633
         slapi_ch_free((void **)&buf;;
232633
 
232633
@@ -952,10 +954,12 @@ views_cache_create_descendent_filter(viewEntry *ancestor, PRBool useEntryID)
232633
                               "views_cache_create_descendent_filter - View filter [%s] in entry [%s] is invalid\n",
232633
                               buf, currentChild->pDn);
232633
             }
232633
-            if (pOrSubFilter && pCurrentFilter)
232633
+            if (pOrSubFilter && pCurrentFilter) {
232633
                 pOrSubFilter = slapi_filter_join_ex(LDAP_FILTER_OR, pOrSubFilter, pCurrentFilter, 0);
232633
-            else
232633
+            } else {
232633
+                slapi_filter_free(pOrSubFilter, 1);
232633
                 pOrSubFilter = pCurrentFilter;
232633
+            }
232633
 
232633
             PR_smprintf_free(buf);
232633
         }
232633
@@ -1756,7 +1760,9 @@ view_search_rewrite_callback(Slapi_PBlock *pb)
232633
 #endif
232633
 
232633
     /* make it happen */
232633
-    slapi_pblock_set(pb, SLAPI_SEARCH_FILTER, outFilter);
232633
+    if (outFilter) {
232633
+        slapi_pblock_set(pb, SLAPI_SEARCH_FILTER, outFilter);
232633
+    }
232633
 
232633
     ret = -2;
232633
 
232633
diff --git a/ldap/servers/slapd/agtmmap.c b/ldap/servers/slapd/agtmmap.c
232633
index 352ccefda..bc5fe1ee1 100644
232633
--- a/ldap/servers/slapd/agtmmap.c
232633
+++ b/ldap/servers/slapd/agtmmap.c
232633
@@ -243,7 +243,7 @@ agt_mread_stats(int hdl, struct hdr_stats_t *pHdrInfo, struct ops_stats_t *pDsOp
232633
         return (EINVAL); /* Inavlid handle */
232633
     }
232633
 
232633
-    if (mmap_tbl[hdl].fp <= (caddr_t)0) {
232633
+    if (mmap_tbl[hdl].fp <= 0) {
232633
         return (EFAULT); /* Something got corrupted */
232633
     }
232633
 
232633
diff --git a/ldap/servers/slapd/back-ldbm/dblayer.c b/ldap/servers/slapd/back-ldbm/dblayer.c
232633
index f813447b6..1fee8050a 100644
232633
--- a/ldap/servers/slapd/back-ldbm/dblayer.c
232633
+++ b/ldap/servers/slapd/back-ldbm/dblayer.c
232633
@@ -3009,7 +3009,7 @@ dblayer_erase_index_file_ex(backend *be, struct attrinfo *a, PRBool use_lock, in
232633
     ldbm_instance *inst = NULL;
232633
     dblayer_handle *handle = NULL;
232633
     char dbName[MAXPATHLEN] = {0};
232633
-    char *dbNamep;
232633
+    char *dbNamep = NULL;
232633
     char *p;
232633
     int dbbasenamelen, dbnamelen;
232633
     int rc = 0;
232633
@@ -3102,11 +3102,12 @@ dblayer_erase_index_file_ex(backend *be, struct attrinfo *a, PRBool use_lock, in
232633
                 sprintf(p, "%c%s%s", get_sep(dbNamep), a->ai_type, LDBM_FILENAME_SUFFIX);
232633
                 rc = dblayer_db_remove_ex(pEnv, dbNamep, 0, 0);
232633
                 a->ai_dblayer = NULL;
232633
-                if (dbNamep != dbName)
232633
-                    slapi_ch_free_string(&dbNamep);
232633
             } else {
232633
                 rc = -1;
232633
             }
232633
+            if (dbNamep != dbName) {
232633
+                slapi_ch_free_string(&dbNamep);
232633
+            }
232633
             slapi_ch_free((void **)&handle);
232633
         } else {
232633
             /* no handle to close */
232633
@@ -5661,7 +5662,9 @@ dblayer_copy_directory(struct ldbminfo *li,
232633
                                               inst_dir, MAXPATHLEN);
232633
         if (!inst_dirp || !*inst_dirp) {
232633
             slapi_log_err(SLAPI_LOG_ERR, "dblayer_copy_directory", "Instance dir is NULL.\n");
232633
-            slapi_ch_free_string(&inst_dirp);
232633
+            if (inst_dirp != inst_dir) {
232633
+                slapi_ch_free_string(&inst_dirp);
232633
+            }
232633
             return return_value;
232633
         }
232633
         len = strlen(inst_dirp);
232633
@@ -5975,7 +5978,9 @@ dblayer_backup(struct ldbminfo *li, char *dest_dir, Slapi_Task *task)
232633
                     slapi_task_log_notice(task,
232633
                                           "Backup: Instance dir is empty\n");
232633
                 }
232633
-                slapi_ch_free_string(&inst_dirp);
232633
+                if (inst_dirp != inst_dir) {
232633
+                    slapi_ch_free_string(&inst_dirp);
232633
+                }
232633
                 return_value = -1;
232633
                 goto bail;
232633
             }
232633
@@ -5993,8 +5998,9 @@ dblayer_backup(struct ldbminfo *li, char *dest_dir, Slapi_Task *task)
232633
                                           "(%s -> %s): err=%d\n",
232633
                                           inst_dirp, dest_dir, return_value);
232633
                 }
232633
-                if (inst_dirp != inst_dir)
232633
+                if (inst_dirp != inst_dir) {
232633
                     slapi_ch_free_string(&inst_dirp);
232633
+                }
232633
                 goto bail;
232633
             }
232633
             if (inst_dirp != inst_dir)
232633
@@ -6292,7 +6298,6 @@ dblayer_copy_dirand_contents(char *src_dir, char *dst_dir, int mode, Slapi_Task
232633
                 break;
232633
             }
232633
 
232633
-
232633
             PR_snprintf(filename1, MAXPATHLEN, "%s/%s", src_dir, direntry->name);
232633
             PR_snprintf(filename2, MAXPATHLEN, "%s/%s", dst_dir, direntry->name);
232633
             slapi_log_err(SLAPI_LOG_ERR, "dblayer_copy_dirand_contents", "Moving file %s\n",
232633
@@ -6305,8 +6310,7 @@ dblayer_copy_dirand_contents(char *src_dir, char *dst_dir, int mode, Slapi_Task
232633
                                                             mode, task);
232633
                 if (return_value) {
232633
                     if (task) {
232633
-                        slapi_task_log_notice(task,
232633
-                                              "Failed to copy directory %s", filename1);
232633
+                        slapi_task_log_notice(task, "Failed to copy directory %s", filename1);
232633
                     }
232633
                     break;
232633
                 }
232633
@@ -6523,13 +6527,13 @@ dblayer_restore(struct ldbminfo *li, char *src_dir, Slapi_Task *task, char *bena
232633
         return LDAP_UNWILLING_TO_PERFORM;
232633
     }
232633
     if (!dbversion_exists(li, src_dir)) {
232633
-        slapi_log_err(SLAPI_LOG_ERR, "dblayer_restore", "Backup directory %s does not "
232633
-                                                        "contain a complete backup\n",
232633
+        slapi_log_err(SLAPI_LOG_ERR, "dblayer_restore",
232633
+                      "Backup directory %s does not contain a complete backup\n",
232633
                       src_dir);
232633
         if (task) {
232633
-            slapi_task_log_notice(task, "Restore: backup directory %s does not "
232633
-                                        "contain a complete backup",
232633
-                                  src_dir);
232633
+            slapi_task_log_notice(task,
232633
+                    "Restore: backup directory %s does not contain a complete backup",
232633
+                    src_dir);
232633
         }
232633
         return LDAP_UNWILLING_TO_PERFORM;
232633
     }
232633
@@ -6585,13 +6589,10 @@ dblayer_restore(struct ldbminfo *li, char *src_dir, Slapi_Task *task, char *bena
232633
                     }
232633
                     if (slapd_comp_path(src_dir, inst->inst_parent_dir_name) == 0) {
232633
                         slapi_log_err(SLAPI_LOG_ERR,
232633
-                                      "dblayer_restore", "Backup dir %s and target dir %s "
232633
-                                                         "are identical\n",
232633
+                                      "dblayer_restore", "Backup dir %s and target dir %s are identical\n",
232633
                                       src_dir, inst->inst_parent_dir_name);
232633
                         if (task) {
232633
                             slapi_task_log_notice(task,
232633
-                                                  "Restore: backup dir %s and target dir %s "
232633
-                                                  "are identical\n",
232633
                                                   src_dir, inst->inst_parent_dir_name);
232633
                         }
232633
                         PR_CloseDir(dirhandle);
232633
@@ -7060,8 +7061,12 @@ dblayer_get_instance_data_dir(backend *be)
232633
     full_namep = dblayer_get_full_inst_dir(inst->inst_li, inst,
232633
                                            full_name, MAXPATHLEN);
232633
     if (!full_namep || !*full_namep) {
232633
+        if (full_namep != full_name) {
232633
+            slapi_ch_free_string(&full_namep);
232633
+        }
232633
         return ret;
232633
     }
232633
+
232633
     /* Does this directory already exist? */
232633
     if ((db_dir = PR_OpenDir(full_namep)) != NULL) {
232633
         /* yep. */
232633
@@ -7072,8 +7077,9 @@ dblayer_get_instance_data_dir(backend *be)
232633
         ret = mkdir_p(full_namep, 0700);
232633
     }
232633
 
232633
-    if (full_name != full_namep)
232633
+    if (full_name != full_namep) {
232633
         slapi_ch_free_string(&full_namep);
232633
+    }
232633
 
232633
     return ret;
232633
 }
232633
@@ -7097,7 +7103,6 @@ dblayer_in_import(ldbm_instance *inst)
232633
     inst_dirp = dblayer_get_full_inst_dir(inst->inst_li, inst,
232633
                                           inst_dir, MAXPATHLEN);
232633
     if (!inst_dirp || !*inst_dirp) {
232633
-        slapi_ch_free_string(&inst_dirp);
232633
         rval = -1;
232633
         goto done;
232633
     }
232633
@@ -7117,8 +7122,9 @@ dblayer_in_import(ldbm_instance *inst)
232633
     }
232633
     PR_CloseDir(dirhandle);
232633
 done:
232633
-    if (inst_dirp != inst_dir)
232633
+    if (inst_dirp != inst_dir) {
232633
         slapi_ch_free_string(&inst_dirp);
232633
+    }
232633
     return rval;
232633
 }
232633
 
232633
@@ -7149,7 +7155,9 @@ dblayer_update_db_ext(ldbm_instance *inst, char *oldext, char *newext)
232633
     if (NULL == inst_dirp || '\0' == *inst_dirp) {
232633
         slapi_log_err(SLAPI_LOG_ERR,
232633
                       "dblayer_update_db_ext", "Instance dir is NULL\n");
232633
-        slapi_ch_free_string(&inst_dirp);
232633
+        if (inst_dirp != inst_dir) {
232633
+            slapi_ch_free_string(&inst_dirp);
232633
+        }
232633
         return -1; /* non zero */
232633
     }
232633
     for (a = (struct attrinfo *)avl_getfirst(inst->inst_attrs);
232633
@@ -7210,8 +7218,9 @@ dblayer_update_db_ext(ldbm_instance *inst, char *oldext, char *newext)
232633
 done:
232633
     slapi_ch_free_string(&ofile);
232633
     slapi_ch_free_string(&nfile);
232633
-    if (inst_dirp != inst_dir)
232633
+    if (inst_dirp != inst_dir) {
232633
         slapi_ch_free_string(&inst_dirp);
232633
+    }
232633
 
232633
     return rval;
232633
 }
232633
diff --git a/ldap/servers/slapd/back-ldbm/index.c b/ldap/servers/slapd/back-ldbm/index.c
232633
index f0b969ff4..2a7529b81 100644
232633
--- a/ldap/servers/slapd/back-ldbm/index.c
232633
+++ b/ldap/servers/slapd/back-ldbm/index.c
232633
@@ -1776,13 +1776,14 @@ index_range_read_ext(
232633
     }
232633
 #endif
232633
 error:
232633
+    slapi_log_err(SLAPI_LOG_TRACE, "index_range_read_ext", "(%s,%s) %lu candidates\n",
232633
+                  type, prefix ? prefix : "", (u_long)IDL_NIDS(idl));
232633
+
232633
     index_free_prefix(prefix);
232633
     DBT_FREE_PAYLOAD(cur_key);
232633
     DBT_FREE_PAYLOAD(upperkey);
232633
-
232633
     dblayer_release_index_file(be, ai, db);
232633
-    slapi_log_err(SLAPI_LOG_TRACE, "index_range_read_ext", "(%s,%s) %lu candidates\n",
232633
-                  type, prefix, (u_long)IDL_NIDS(idl));
232633
+
232633
     return (idl);
232633
 }
232633
 
232633
@@ -2406,7 +2407,7 @@ index_free_prefix(char *prefix)
232633
         prefix == prefix_SUB) {
232633
         /* do nothing */
232633
     } else {
232633
-        slapi_ch_free((void **)&prefix);
232633
+        slapi_ch_free_string(&prefix);
232633
     }
232633
 }
232633
 
232633
diff --git a/ldap/servers/slapd/back-ldbm/ldbm_add.c b/ldap/servers/slapd/back-ldbm/ldbm_add.c
232633
index 0d82ae92b..a2585575f 100644
232633
--- a/ldap/servers/slapd/back-ldbm/ldbm_add.c
232633
+++ b/ldap/servers/slapd/back-ldbm/ldbm_add.c
232633
@@ -162,7 +162,8 @@ ldbm_back_add(Slapi_PBlock *pb)
232633
         txn.back_txn_txn = parent_txn;
232633
     } else {
232633
         parent_txn = txn.back_txn_txn;
232633
-        slapi_pblock_set(pb, SLAPI_TXN, parent_txn);
232633
+        if (parent_txn)
232633
+            slapi_pblock_set(pb, SLAPI_TXN, parent_txn);
232633
     }
232633
 
232633
     /* The dblock serializes writes to the database,
232633
diff --git a/ldap/servers/slapd/back-ldbm/ldbm_attrcrypt_config.c b/ldap/servers/slapd/back-ldbm/ldbm_attrcrypt_config.c
232633
index 9ecb09903..fd2c7dbc8 100644
232633
--- a/ldap/servers/slapd/back-ldbm/ldbm_attrcrypt_config.c
232633
+++ b/ldap/servers/slapd/back-ldbm/ldbm_attrcrypt_config.c
232633
@@ -142,7 +142,7 @@ ldbm_instance_attrcrypt_config_add_callback(Slapi_PBlock *pb __attribute__((unus
232633
 
232633
         /* If the cipher was invalid, return unwilling to perform */
232633
         if (0 == cipher) {
232633
-            returntext = "invalid cipher";
232633
+            PR_snprintf(returntext, SLAPI_DSE_RETURNTEXT_SIZE, "invalid cipher");
232633
             *returncode = LDAP_UNWILLING_TO_PERFORM;
232633
             ret = SLAPI_DSE_CALLBACK_ERROR;
232633
         } else {
232633
@@ -167,7 +167,7 @@ ldbm_instance_attrcrypt_config_add_callback(Slapi_PBlock *pb __attribute__((unus
232633
                 slapi_log_err(SLAPI_LOG_ERR, "ldbm_instance_attrcrypt_config_add_callback - "
232633
                                              "Attempt to encryption on a non-existent attribute: %s\n",
232633
                               attribute_name, 0, 0);
232633
-                returntext = "attribute does not exist";
232633
+                PR_snprintf(returntext, SLAPI_DSE_RETURNTEXT_SIZE, "attribute does not exist");
232633
                 *returncode = LDAP_UNWILLING_TO_PERFORM;
232633
                 ret = SLAPI_DSE_CALLBACK_ERROR;
232633
             }
232633
diff --git a/ldap/servers/slapd/back-ldbm/ldbm_delete.c b/ldap/servers/slapd/back-ldbm/ldbm_delete.c
232633
index e9f3e32cc..76e37ae14 100644
232633
--- a/ldap/servers/slapd/back-ldbm/ldbm_delete.c
232633
+++ b/ldap/servers/slapd/back-ldbm/ldbm_delete.c
232633
@@ -113,7 +113,8 @@ ldbm_back_delete(Slapi_PBlock *pb)
232633
         txn.back_txn_txn = parent_txn;
232633
     } else {
232633
         parent_txn = txn.back_txn_txn;
232633
-        slapi_pblock_set(pb, SLAPI_TXN, parent_txn);
232633
+        if (parent_txn)
232633
+            slapi_pblock_set(pb, SLAPI_TXN, parent_txn);
232633
     }
232633
 
232633
     if (pb_conn) {
232633
diff --git a/ldap/servers/slapd/back-ldbm/ldif2ldbm.c b/ldap/servers/slapd/back-ldbm/ldif2ldbm.c
232633
index 60437f116..fb0fc5d1e 100644
232633
--- a/ldap/servers/slapd/back-ldbm/ldif2ldbm.c
232633
+++ b/ldap/servers/slapd/back-ldbm/ldif2ldbm.c
232633
@@ -1154,7 +1154,7 @@ ldbm_back_ldbm2ldif(Slapi_PBlock *pb)
232633
     int task_flags;
232633
     Slapi_Task *task;
232633
     int run_from_cmdline = 0;
232633
-    char *instance_name;
232633
+    char *instance_name = NULL;
232633
     ldbm_instance *inst = NULL;
232633
     int str2entry_options = 0;
232633
     int retry;
232633
@@ -1203,11 +1203,11 @@ ldbm_back_ldbm2ldif(Slapi_PBlock *pb)
232633
         goto bye;
232633
     }
232633
 
232633
+    slapi_pblock_get(pb, SLAPI_BACKEND_INSTANCE_NAME, &instance_name);
232633
     if (run_from_cmdline) {
232633
 
232633
         /* Now that we have processed the config information, we look for
232633
          * the be that should do the db2ldif. */
232633
-        slapi_pblock_get(pb, SLAPI_BACKEND_INSTANCE_NAME, &instance_name);
232633
         inst = ldbm_instance_find_by_name(li, instance_name);
232633
         if (NULL == inst) {
232633
             slapi_task_log_notice(task, "Unknown backend instance: %s", instance_name);
232633
diff --git a/ldap/servers/slapd/back-ldbm/vlv_srch.c b/ldap/servers/slapd/back-ldbm/vlv_srch.c
232633
index 368417483..1ac3e009e 100644
232633
--- a/ldap/servers/slapd/back-ldbm/vlv_srch.c
232633
+++ b/ldap/servers/slapd/back-ldbm/vlv_srch.c
232633
@@ -168,7 +168,8 @@ vlvSearch_init(struct vlvSearch *p, Slapi_PBlock *pb, const Slapi_Entry *e, ldbm
232633
 
232633
             /* switch context back to the DSE backend */
232633
             slapi_pblock_set(pb, SLAPI_BACKEND, oldbe);
232633
-            slapi_pblock_set(pb, SLAPI_PLUGIN, oldbe ? oldbe->be_database: NULL);
232633
+            if (oldbe)
232633
+                slapi_pblock_set(pb, SLAPI_PLUGIN, oldbe->be_database);
232633
         }
232633
 
232633
         /* make (&(parentid=idofbase)(|(originalfilter)(objectclass=referral))) */
232633
diff --git a/ldap/servers/slapd/connection.c b/ldap/servers/slapd/connection.c
232633
index 4a611e7f4..d3bf82b67 100644
232633
--- a/ldap/servers/slapd/connection.c
232633
+++ b/ldap/servers/slapd/connection.c
232633
@@ -1864,6 +1864,7 @@ connection_threadmain()
232633
                         signal_listner();
232633
                     }
232633
                 } else if (1 == is_timedout) {
232633
+                    /* covscan reports this code is unreachable  (2019/6/4) */
232633
                     connection_make_readable_nolock(conn);
232633
                     signal_listner();
232633
                 }
232633
diff --git a/ldap/servers/slapd/dse.c b/ldap/servers/slapd/dse.c
232633
index 1f1f51630..125684329 100644
232633
--- a/ldap/servers/slapd/dse.c
232633
+++ b/ldap/servers/slapd/dse.c
232633
@@ -2530,7 +2530,8 @@ dse_delete(Slapi_PBlock *pb) /* JCM There should only be one exit point from thi
232633
     dse_call_callback(pdse, pb, SLAPI_OPERATION_DELETE, DSE_FLAG_POSTOP, ec, NULL, &returncode, returntext);
232633
 done:
232633
     slapi_pblock_get(pb, SLAPI_DELETE_BEPOSTOP_ENTRY, &orig_entry);
232633
-    slapi_pblock_set(pb, SLAPI_DELETE_BEPOSTOP_ENTRY, ec);
232633
+    if (ec)
232633
+        slapi_pblock_set(pb, SLAPI_DELETE_BEPOSTOP_ENTRY, ec);
232633
     /* make sure OPRETURN and RESULT_CODE are set */
232633
     slapi_pblock_get(pb, SLAPI_PLUGIN_OPRETURN, &rc);
232633
     if (returncode || rc) {
232633
@@ -2571,8 +2572,8 @@ done:
232633
             rc = LDAP_UNWILLING_TO_PERFORM;
232633
         }
232633
     }
232633
-
232633
-    slapi_pblock_set(pb, SLAPI_DELETE_BEPOSTOP_ENTRY, orig_entry);
232633
+    if (orig_entry)
232633
+        slapi_pblock_set(pb, SLAPI_DELETE_BEPOSTOP_ENTRY, orig_entry);
232633
     slapi_send_ldap_result(pb, returncode, NULL, returntext, 0, NULL);
232633
     return dse_delete_return(returncode, ec);
232633
 }
232633
diff --git a/ldap/servers/slapd/entrywsi.c b/ldap/servers/slapd/entrywsi.c
232633
index 080eb15aa..5d1d7238a 100644
232633
--- a/ldap/servers/slapd/entrywsi.c
232633
+++ b/ldap/servers/slapd/entrywsi.c
232633
@@ -359,7 +359,6 @@ entry_add_present_attribute_wsi(Slapi_Entry *e, Slapi_Attr *a)
232633
  * Preserves LDAP Information Model constraints,
232633
  * returning an LDAP result code.
232633
  */
232633
-static void entry_dump_stateinfo(char *msg, Slapi_Entry* e);
232633
 static Slapi_Value *attr_most_recent_deleted_value(Slapi_Attr *a);
232633
 static void resolve_single_valued_two_values(Slapi_Entry *e, Slapi_Attr *a, int attribute_state, Slapi_Value *current_value, Slapi_Value *second_current_value);
232633
 static void resolve_single_valued_check_restore_deleted_value(Slapi_Entry *e, Slapi_Attr *a);
232633
@@ -397,6 +396,7 @@ entry_add_present_values_wsi(Slapi_Entry *e, const char *type, struct berval **b
232633
 /* Used for debug purpose, it dumps into the error log the
232633
  * entry with the replication stateinfo
232633
  */
232633
+#if 0
232633
 static void
232633
 entry_dump_stateinfo(char *msg, Slapi_Entry* e)
232633
 {
232633
@@ -407,6 +407,7 @@ entry_dump_stateinfo(char *msg, Slapi_Entry* e)
232633
 	slapi_log_err(SLAPI_LOG_ERR, msg, "%s\n", s);
232633
 	slapi_ch_free((void **)&s);
232633
 }
232633
+#endif
232633
 
232633
 static int
232633
 entry_add_present_values_wsi_single_valued(Slapi_Entry *e, const char *type, struct berval **bervals, const CSN *csn, int urp, long flags)
232633
@@ -1270,7 +1271,7 @@ attr_most_recent_deleted_value(Slapi_Attr *a)
232633
     most_recent_v = v;
232633
 
232633
     while (i != -1) {
232633
-        vdcsn = value_get_csn(v, CSN_TYPE_VALUE_DELETED);
232633
+        vdcsn = (CSN *)value_get_csn(v, CSN_TYPE_VALUE_DELETED);
232633
 
232633
         if (csn_compare((const CSN *)most_recent_vdcsn, (const CSN *)vdcsn) < 0) {
232633
             most_recent_v = v;
232633
@@ -1289,20 +1290,20 @@ static void
232633
 resolve_single_valued_two_values(Slapi_Entry *e, Slapi_Attr *a, int attribute_state, Slapi_Value *current_value, Slapi_Value *second_current_value)
232633
 {
232633
 
232633
-    CSN *current_value_vucsn;
232633
-    CSN *second_current_value_vucsn;
232633
+    const CSN *current_value_vucsn;
232633
+    const CSN *second_current_value_vucsn;
232633
     Slapi_Value *value_to_zap;
232633
     
232633
     current_value_vucsn = value_get_csn(current_value, CSN_TYPE_VALUE_UPDATED);
232633
     second_current_value_vucsn = value_get_csn(second_current_value, CSN_TYPE_VALUE_UPDATED);
232633
     
232633
     /* First determine which present value will be zapped */
232633
-    if (csn_compare((const CSN *)second_current_value_vucsn, (const CSN *)current_value_vucsn) < 0) {
232633
+    if (csn_compare(second_current_value_vucsn, current_value_vucsn) < 0) {
232633
         /*
232633
          * The second value is older but was distinguished at the time the current value was added
232633
          * then the second value should become current
232633
          */
232633
-        if (value_distinguished_at_csn(e, a, second_current_value, (const CSN *)current_value_vucsn)) {
232633
+        if (value_distinguished_at_csn(e, a, second_current_value, current_value_vucsn)) {
232633
             value_to_zap = current_value;
232633
         } else {
232633
             /* The second value being not distinguished, zap it as it is a single valued attribute */
232633
@@ -1311,7 +1312,7 @@ resolve_single_valued_two_values(Slapi_Entry *e, Slapi_Attr *a, int attribute_st
232633
         
232633
     } else {
232633
         /* Here the current_value is older than the second_current_value */
232633
-        if (value_distinguished_at_csn(e, a, current_value, (const CSN *)second_current_value_vucsn)) {
232633
+        if (value_distinguished_at_csn(e, a, current_value, second_current_value_vucsn)) {
232633
             /* current_value was distinguished at the time the second value was added
232633
              * then the current_value should become the current */
232633
             value_to_zap = second_current_value;
232633
@@ -1348,17 +1349,17 @@ resolve_single_valued_check_restore_deleted_value(Slapi_Entry *e, Slapi_Attr *a)
232633
         /* An attribute needs a present value */
232633
         entry_deleted_value_to_present_value(a, deleted_value);
232633
     } else {
232633
-        CSN *current_value_vucsn;
232633
-        CSN *deleted_value_vucsn;
232633
-        CSN *deleted_value_vdcsn;
232633
+        const CSN *current_value_vucsn;
232633
+        const CSN *deleted_value_vucsn;
232633
+        const CSN *deleted_value_vdcsn;
232633
 
232633
         deleted_value_vucsn = value_get_csn(deleted_value, CSN_TYPE_VALUE_UPDATED);
232633
         deleted_value_vdcsn = value_get_csn(deleted_value, CSN_TYPE_VALUE_DELETED);
232633
         current_value_vucsn = value_get_csn(current_value, CSN_TYPE_VALUE_UPDATED);
232633
         if (deleted_value_vucsn &&
232633
-                !value_distinguished_at_csn(e, a, current_value, (const CSN *)deleted_value_vucsn) &&
232633
-                (csn_compare((const CSN *)current_value_vucsn, (const CSN *)deleted_value_vucsn) < 0) &&
232633
-                (csn_compare((const CSN *)deleted_value_vdcsn, (const CSN *)current_value_vucsn) < 0)) {
232633
+                !value_distinguished_at_csn(e, a, current_value, deleted_value_vucsn) &&
232633
+                (csn_compare((const CSN *)current_value_vucsn, deleted_value_vucsn) < 0) &&
232633
+                (csn_compare((const CSN *)deleted_value_vdcsn, current_value_vucsn) < 0)) {
232633
             /* the condition to resurrect the deleted value is 
232633
              *  - it is more recent than the current value
232633
              *  - its value was deleted before the current value
232633
@@ -1376,8 +1377,8 @@ static void
232633
 resolve_single_valued_zap_current(Slapi_Entry *e, Slapi_Attr *a)
232633
 {
232633
     Slapi_Value *current_value = NULL;
232633
-    CSN *current_value_vucsn;
232633
-    CSN *adcsn;
232633
+    const CSN *current_value_vucsn;
232633
+    const CSN *adcsn;
232633
 
232633
     /* check if the current value should be deleted because 
232633
      * older than adcsn and not distinguished
232633
@@ -1386,7 +1387,7 @@ resolve_single_valued_zap_current(Slapi_Entry *e, Slapi_Attr *a)
232633
     current_value_vucsn = value_get_csn(current_value, CSN_TYPE_VALUE_UPDATED);
232633
     adcsn = attr_get_deletion_csn(a);
232633
     if (current_value != NULL) {
232633
-        if (csn_compare((const CSN *)adcsn, (const CSN *) current_value_vucsn) > 0) {
232633
+        if (csn_compare(adcsn, (const CSN *) current_value_vucsn) > 0) {
232633
             /* the attribute was deleted after the value was last updated */
232633
             if (!value_distinguished_at_csn(e, a, current_value, (const CSN *) current_value_vucsn)) {
232633
                 entry_present_value_to_zapped_value(a, current_value);
232633
@@ -1404,17 +1405,17 @@ resolve_single_valued_set_adcsn(Slapi_Attr *a)
232633
 {
232633
     Slapi_Value *deleted_value = NULL;
232633
     Slapi_Value *current_value = NULL;
232633
-    CSN *current_value_vucsn;
232633
-    CSN *deleted_value_vucsn;
232633
-    CSN *adcsn;
232633
+    const CSN *current_value_vucsn;
232633
+    const CSN *deleted_value_vucsn;
232633
+    const CSN *adcsn;
232633
     
232633
     slapi_attr_first_value(a, &current_value);
232633
     current_value_vucsn = value_get_csn(current_value, CSN_TYPE_VALUE_UPDATED);
232633
     deleted_value = attr_most_recent_deleted_value(a);
232633
     deleted_value_vucsn = value_get_csn(deleted_value, CSN_TYPE_VALUE_UPDATED);
232633
     adcsn = attr_get_deletion_csn(a);
232633
-    if ((deleted_value != NULL && (csn_compare(adcsn, (const CSN *) deleted_value_vucsn) < 0)) ||
232633
-        (deleted_value == NULL && (csn_compare(adcsn, (const CSN *) current_value_vucsn) < 0))) {
232633
+    if ((deleted_value != NULL && (csn_compare(adcsn, deleted_value_vucsn) < 0)) ||
232633
+        (deleted_value == NULL && (csn_compare(adcsn, current_value_vucsn) < 0))) {
232633
         attr_set_deletion_csn(a, NULL);
232633
     }
232633
 }
232633
@@ -1430,10 +1431,10 @@ resolve_single_valued_zap_deleted(Slapi_Attr *a)
232633
 {
232633
     Slapi_Value *deleted_value = NULL;
232633
     Slapi_Value *current_value = NULL;
232633
-    CSN *current_value_vucsn;
232633
-    CSN *deleted_value_vucsn;
232633
-    CSN *deleted_value_vdcsn;
232633
-    CSN *deleted_value_csn;
232633
+    const CSN *current_value_vucsn;
232633
+    const CSN *deleted_value_vucsn;
232633
+    const CSN *deleted_value_vdcsn;
232633
+    const CSN *deleted_value_csn;
232633
     PRBool deleted_on_mod_del = PR_FALSE; /* flag if a value was deleted specifically */
232633
 
232633
     /* Now determine if the deleted value worth to be kept */
232633
@@ -1445,16 +1446,16 @@ resolve_single_valued_zap_deleted(Slapi_Attr *a)
232633
     deleted_value_vdcsn = value_get_csn(deleted_value, CSN_TYPE_VALUE_DELETED);
232633
 
232633
     /* get the appropriate csn to take into consideration: either from MOD_REPL or from MOD_DEL_specific */
232633
-    if (csn_compare((const CSN *) deleted_value_vdcsn, (const CSN *) deleted_value_vucsn) <= 0) {
232633
+    if (csn_compare(deleted_value_vdcsn, deleted_value_vucsn) <= 0) {
232633
         deleted_value_csn = deleted_value_vucsn;
232633
     } else {
232633
         deleted_value_csn = deleted_value_vdcsn;
232633
-        if (0 == csn_compare_ext((const CSN *) current_value_vucsn, (const CSN *) deleted_value_vdcsn, CSN_COMPARE_SKIP_SUBSEQ)) {
232633
+        if (0 == csn_compare_ext(current_value_vucsn, deleted_value_vdcsn, CSN_COMPARE_SKIP_SUBSEQ)) {
232633
             /* the deleted value was specifically delete in the same operation that set the current value */
232633
             deleted_on_mod_del = PR_TRUE;
232633
         }
232633
     }
232633
-    if ((csn_compare((const CSN *) deleted_value_csn, (const CSN *) current_value_vucsn) < 0) || deleted_on_mod_del) {
232633
+    if ((csn_compare(deleted_value_csn, current_value_vucsn) < 0) || deleted_on_mod_del) {
232633
         entry_deleted_value_to_zapped_value(a, deleted_value);
232633
     }
232633
 }
232633
diff --git a/ldap/servers/slapd/main.c b/ldap/servers/slapd/main.c
232633
index 33ca9ce1d..2c7b53214 100644
232633
--- a/ldap/servers/slapd/main.c
232633
+++ b/ldap/servers/slapd/main.c
232633
@@ -1220,6 +1220,7 @@ main(int argc, char **argv)
232633
     vattr_cleanup();
232633
     sasl_map_done();
232633
 cleanup:
232633
+    slapi_ch_free_string(&(mcfg.myname));
232633
     compute_terminate();
232633
     SSL_ShutdownServerSessionIDCache();
232633
     SSL_ClearSessionCache();
232633
@@ -2194,7 +2195,6 @@ slapd_exemode_ldif2db(struct main_config *mcfg)
232633
         return_value = -1;
232633
     }
232633
     slapi_pblock_destroy(pb);
232633
-    slapi_ch_free((void **)&(mcfg->myname));
232633
     charray_free(instances);
232633
     charray_free(mcfg->cmd_line_instance_names);
232633
     charray_free(mcfg->db2ldif_include);
232633
@@ -2377,7 +2377,6 @@ slapd_exemode_db2ldif(int argc, char **argv, struct main_config *mcfg)
232633
             slapi_ch_free((void **)&my_ldiffile);
232633
         }
232633
     }
232633
-    slapi_ch_free((void **)&(mcfg->myname));
232633
     charray_free(mcfg->cmd_line_instance_names);
232633
     charray_free(mcfg->db2ldif_include);
232633
     if (mcfg->db2ldif_dump_replica) {
232633
@@ -2505,8 +2504,6 @@ slapd_exemode_db2index(struct main_config *mcfg)
232633
 
232633
     slapi_pblock_destroy(pb);
232633
     charray_free(mcfg->db2index_attrs);
232633
-    slapi_ch_free((void **)&(mcfg->myname));
232633
-
232633
     charray_free(mcfg->db2ldif_include);
232633
     /* This frees  mcfg->cmd_line_instance_name */
232633
     charray_free(instances);
232633
@@ -2557,7 +2554,6 @@ slapd_exemode_db2archive(struct main_config *mcfg)
232633
     int32_t task_flags = SLAPI_TASK_RUNNING_FROM_COMMANDLINE;
232633
     slapi_pblock_set(pb, SLAPI_TASK_FLAGS, &task_flags);
232633
     return_value = (backend_plugin->plg_db2archive)(pb);
232633
-    slapi_ch_free((void **)&(mcfg->myname));
232633
     slapi_pblock_destroy(pb);
232633
     return return_value;
232633
 }
232633
@@ -2605,7 +2601,6 @@ slapd_exemode_archive2db(struct main_config *mcfg)
232633
     slapi_pblock_set(pb, SLAPI_TASK_FLAGS, &task_flags);
232633
     slapi_pblock_set(pb, SLAPI_BACKEND_INSTANCE_NAME, mcfg->cmd_line_instance_name);
232633
     return_value = (backend_plugin->plg_archive2db)(pb);
232633
-    slapi_ch_free((void **)&(mcfg->myname));
232633
     slapi_pblock_destroy(pb);
232633
     return return_value;
232633
 }
232633
@@ -2674,7 +2669,6 @@ slapd_exemode_upgradedb(struct main_config *mcfg)
232633
         return_value = -1;
232633
     }
232633
     slapi_pblock_destroy(pb);
232633
-    slapi_ch_free((void **)&(mcfg->myname));
232633
     return (return_value);
232633
 }
232633
 
232633
@@ -2747,7 +2741,6 @@ slapd_exemode_upgradednformat(struct main_config *mcfg)
232633
     }
232633
     slapi_pblock_destroy(pb);
232633
 bail:
232633
-    slapi_ch_free((void **)&(mcfg->myname));
232633
     return (rc);
232633
 }
232633
 
232633
diff --git a/ldap/servers/slapd/mapping_tree.c b/ldap/servers/slapd/mapping_tree.c
232633
index 834949a67..b90424985 100644
232633
--- a/ldap/servers/slapd/mapping_tree.c
232633
+++ b/ldap/servers/slapd/mapping_tree.c
232633
@@ -539,9 +539,6 @@ free_mapping_tree_node_arrays(backend ***be_list, char ***be_names, int **be_sta
232633
 {
232633
     int i;
232633
 
232633
-    /* sanity check */
232633
-    PR_ASSERT(be_list != NULL && be_names != NULL && be_states != NULL && be_list_count != NULL);
232633
-
232633
     if (*be_names != NULL)
232633
         for (i = 0; i < *be_list_count; ++i) {
232633
             slapi_ch_free((void **)&((*be_names)[i]));
232633
@@ -647,9 +644,7 @@ mapping_tree_entry_add(Slapi_Entry *entry, mapping_tree_node **newnodep)
232633
 
232633
             if (get_backends_from_attr(attr, &be_list, &be_names, &be_states,
232633
                                        &be_list_count, &be_list_size, NULL)) {
232633
-                free_mapping_tree_node_arrays(&be_list, &be_names, &be_states, &be_list_count);
232633
-                slapi_sdn_free(&subtree);
232633
-                return lderr;
232633
+                goto free_and_return;
232633
             }
232633
 
232633
             if (NULL == be_list) {
232633
@@ -660,6 +655,7 @@ mapping_tree_entry_add(Slapi_Entry *entry, mapping_tree_node **newnodep)
232633
             }
232633
 
232633
         } else if (!strcasecmp(type, "nsslapd-referral")) {
232633
+            slapi_ch_array_free(referral);
232633
             referral = mtn_get_referral_from_entry(entry);
232633
 
232633
         } else if (!strcasecmp(type, "nsslapd-state")) {
232633
@@ -684,6 +680,7 @@ mapping_tree_entry_add(Slapi_Entry *entry, mapping_tree_node **newnodep)
232633
                               slapi_entry_get_dn(entry));
232633
                 continue;
232633
             }
232633
+            slapi_ch_free_string(&plugin_lib);
232633
             plugin_lib = slapi_ch_strdup(slapi_value_get_string(val));
232633
         } else if (!strcasecmp(type, "nsslapd-distribution-funct")) {
232633
             slapi_attr_first_value(attr, &val;;
232633
@@ -693,6 +690,7 @@ mapping_tree_entry_add(Slapi_Entry *entry, mapping_tree_node **newnodep)
232633
                               slapi_entry_get_dn(entry));
232633
                 continue;
232633
             }
232633
+            slapi_ch_free_string(&plugin_funct);
232633
             plugin_funct = slapi_ch_strdup(slapi_value_get_string(val));
232633
         } else if (!strcasecmp(type, "nsslapd-distribution-root-update")) {
232633
             const char *sval;
232633
@@ -737,13 +735,16 @@ mapping_tree_entry_add(Slapi_Entry *entry, mapping_tree_node **newnodep)
232633
         if (be == NULL) {
232633
             slapi_log_err(SLAPI_LOG_ERR, "mapping_tree_entry_add",
232633
                           "Default container has not been created for the NULL SUFFIX node.\n");
232633
-            slapi_sdn_free(&subtree);
232633
-            return -1;
232633
+            lderr = -1;
232633
+            goto free_and_return;
232633
         }
232633
 
232633
         be_list_size = 1;
232633
         be_list_count = 0;
232633
 
232633
+        /* We're in a loop and potentially overwriting these pointers so free them first */
232633
+        free_mapping_tree_node_arrays(&be_list, &be_names, &be_states, &be_list_count);
232633
+
232633
         be_list = (backend **)slapi_ch_calloc(1, sizeof(backend *));
232633
         be_names = (char **)slapi_ch_calloc(1, sizeof(char *));
232633
         be_states = (int *)slapi_ch_calloc(1, sizeof(int));
232633
@@ -767,17 +768,13 @@ mapping_tree_entry_add(Slapi_Entry *entry, mapping_tree_node **newnodep)
232633
         slapi_log_err(SLAPI_LOG_ERR,
232633
                       "Node %s must define a backend\n",
232633
                       slapi_entry_get_dn(entry), 0, 0);
232633
-        slapi_sdn_free(&subtree);
232633
-        free_mapping_tree_node_arrays(&be_list, &be_names, &be_states, &be_list_count);
232633
-        return lderr;
232633
+        goto free_and_return;
232633
     }
232633
     if (((state == MTN_REFERRAL) || (state == MTN_REFERRAL_ON_UPDATE)) && (referral == NULL)) {
232633
         slapi_log_err(SLAPI_LOG_ERR,
232633
                       "Node %s must define referrals to be in referral state\n",
232633
                       slapi_entry_get_dn(entry), 0, 0);
232633
-        slapi_sdn_free(&subtree);
232633
-        free_mapping_tree_node_arrays(&be_list, &be_names, &be_states, &be_list_count);
232633
-        return lderr;
232633
+        goto free_and_return;
232633
     }
232633
 
232633
     if (plugin_lib && plugin_funct) {
232633
@@ -787,11 +784,7 @@ mapping_tree_entry_add(Slapi_Entry *entry, mapping_tree_node **newnodep)
232633
             slapi_log_err(SLAPI_LOG_ERR, "mapping_tree_entry_add",
232633
                           "Node %s cannot find distribution plugin. " SLAPI_COMPONENT_NAME_NSPR " %d (%s)\n",
232633
                           slapi_entry_get_dn(entry), PR_GetError(), slapd_pr_strerror(PR_GetError()));
232633
-            slapi_sdn_free(&subtree);
232633
-            slapi_ch_free((void **)&plugin_funct);
232633
-            slapi_ch_free((void **)&plugin_lib);
232633
-            free_mapping_tree_node_arrays(&be_list, &be_names, &be_states, &be_list_count);
232633
-            return lderr;
232633
+            goto free_and_return;
232633
         }
232633
     } else if ((plugin_lib == NULL) && (plugin_funct == NULL)) {
232633
         /* nothing configured -> OK */
232633
@@ -801,11 +794,7 @@ mapping_tree_entry_add(Slapi_Entry *entry, mapping_tree_node **newnodep)
232633
         slapi_log_err(SLAPI_LOG_ERR, "mapping_tree_entry_add",
232633
                       "Node %s must define both lib and funct for distribution plugin\n",
232633
                       slapi_entry_get_dn(entry));
232633
-        slapi_sdn_free(&subtree);
232633
-        slapi_ch_free((void **)&plugin_funct);
232633
-        slapi_ch_free((void **)&plugin_lib);
232633
-        free_mapping_tree_node_arrays(&be_list, &be_names, &be_states, &be_list_count);
232633
-        return lderr;
232633
+        goto free_and_return;
232633
     }
232633
 
232633
     /* Now we can create the node for this mapping tree entry. */
232633
@@ -838,6 +827,15 @@ mapping_tree_entry_add(Slapi_Entry *entry, mapping_tree_node **newnodep)
232633
         *newnodep = node;
232633
     }
232633
 
232633
+    return lderr;
232633
+
232633
+free_and_return:
232633
+    slapi_sdn_free(&subtree);
232633
+    slapi_ch_array_free(referral);
232633
+    slapi_ch_free_string(&plugin_funct);
232633
+    slapi_ch_free_string(&plugin_lib);
232633
+    free_mapping_tree_node_arrays(&be_list, &be_names, &be_states, &be_list_count);
232633
+
232633
     return lderr;
232633
 }
232633
 
232633
diff --git a/ldap/servers/slapd/modify.c b/ldap/servers/slapd/modify.c
232633
index 896cccfb9..bbc0ab71a 100644
232633
--- a/ldap/servers/slapd/modify.c
232633
+++ b/ldap/servers/slapd/modify.c
232633
@@ -1444,9 +1444,11 @@ optimize_mods(Slapi_Mods *smods)
232633
 
232633
     prev_mod = slapi_mods_get_first_mod(smods);
232633
     while ((mod = slapi_mods_get_next_mod(smods))) {
232633
-        if ((SLAPI_IS_MOD_ADD(prev_mod->mod_op) || SLAPI_IS_MOD_DELETE(prev_mod->mod_op)) &&
232633
+        if (prev_mod &&
232633
+            (SLAPI_IS_MOD_ADD(prev_mod->mod_op) || SLAPI_IS_MOD_DELETE(prev_mod->mod_op)) &&
232633
             (prev_mod->mod_op == mod->mod_op) &&
232633
-            (!strcasecmp(prev_mod->mod_type, mod->mod_type))) {
232633
+            (!strcasecmp(prev_mod->mod_type, mod->mod_type)))
232633
+        {
232633
             /* Get the current number of mod values from the previous mod.  Do it once per attr */
232633
             if (mod_count == 0) {
232633
                 for (; prev_mod->mod_bvalues != NULL && prev_mod->mod_bvalues[mod_count] != NULL; mod_count++)
232633
diff --git a/ldap/servers/slapd/opshared.c b/ldap/servers/slapd/opshared.c
232633
index dd6917363..dac42eb13 100644
232633
--- a/ldap/servers/slapd/opshared.c
232633
+++ b/ldap/servers/slapd/opshared.c
232633
@@ -998,7 +998,8 @@ free_and_return_nolock:
232633
         slapi_sdn_free(&sdn;;
232633
     }
232633
     slapi_sdn_free(&basesdn);
232633
-    slapi_pblock_set(pb, SLAPI_SEARCH_TARGET_SDN, orig_sdn);
232633
+    if (orig_sdn)
232633
+        slapi_pblock_set(pb, SLAPI_SEARCH_TARGET_SDN, orig_sdn);
232633
 
232633
     slapi_ch_free_string(&proxydn);
232633
     slapi_ch_free_string(&proxystr);
232633
diff --git a/ldap/servers/slapd/plugin_internal_op.c b/ldap/servers/slapd/plugin_internal_op.c
232633
index 9da266b61..622daffdb 100644
232633
--- a/ldap/servers/slapd/plugin_internal_op.c
232633
+++ b/ldap/servers/slapd/plugin_internal_op.c
232633
@@ -368,7 +368,8 @@ seq_internal_callback_pb(Slapi_PBlock *pb, void *callback_data, plugin_result_ca
232633
     slapi_pblock_set(pb, SLAPI_BACKEND, be);
232633
     slapi_pblock_set(pb, SLAPI_PLUGIN, be->be_database);
232633
     slapi_pblock_set(pb, SLAPI_SEQ_ATTRNAME, attrname);
232633
-    slapi_pblock_set(pb, SLAPI_SEQ_VAL, val);
232633
+    if (val)
232633
+        slapi_pblock_set(pb, SLAPI_SEQ_VAL, val);
232633
     slapi_pblock_set(pb, SLAPI_REQCONTROLS, controls);
232633
 
232633
     /* set actions taken to process the operation */
232633
diff --git a/ldap/servers/slapd/plugin_syntax.c b/ldap/servers/slapd/plugin_syntax.c
232633
index e208442d5..dc7106da5 100644
232633
--- a/ldap/servers/slapd/plugin_syntax.c
232633
+++ b/ldap/servers/slapd/plugin_syntax.c
232633
@@ -247,7 +247,9 @@ plugin_call_syntax_filter_sub_sv(
232633
             Operation *op = NULL;
232633
             /* to pass SLAPI_SEARCH_TIMELIMIT & SLAPI_OPINITATED_TIME */
232633
             slapi_pblock_get(pb, SLAPI_OPERATION, &op);
232633
-            slapi_pblock_set(pipb, SLAPI_OPERATION, op);
232633
+            if (op) {
232633
+                slapi_pblock_set(pipb, SLAPI_OPERATION, op);
232633
+            }
232633
         }
232633
         rc = (*sub_fn)(pipb, fsub->sf_initial, fsub->sf_any, fsub->sf_final, va);
232633
     } else {
232633
diff --git a/ldap/servers/slapd/rdn.c b/ldap/servers/slapd/rdn.c
232633
index 41c075036..fdb6b1773 100644
232633
--- a/ldap/servers/slapd/rdn.c
232633
+++ b/ldap/servers/slapd/rdn.c
232633
@@ -934,10 +934,7 @@ slapi_rdn_get_dn(Slapi_RDN *srdn, char **dn)
232633
     if (NULL == srdn || NULL == srdn->all_rdns || NULL == dn) {
232633
         return -1;
232633
     }
232633
-    for (rdnp = srdn->all_rdns; rdnp && *rdnp; rdnp++) {
232633
-        len += strlen(*rdnp) + 1; /* 1 for ',' */
232633
-    }
232633
-    len += 1;
232633
+
232633
     len = slapi_rdn_get_dn_len(srdn);
232633
     *dn = (char *)slapi_ch_malloc(len);
232633
     enddn = *dn + len - 1;
232633
diff --git a/ldap/servers/slapd/sasl_map.c b/ldap/servers/slapd/sasl_map.c
232633
index 72bd01079..9593fd075 100644
232633
--- a/ldap/servers/slapd/sasl_map.c
232633
+++ b/ldap/servers/slapd/sasl_map.c
232633
@@ -336,7 +336,9 @@ _sasl_unescape_parenthesis(char *input)
232633
             *d++ = *s;
232633
         }
232633
     }
232633
-    *d = '\0';
232633
+    if (d) {
232633
+        *d = '\0';
232633
+    }
232633
     return input;
232633
 }
232633
 
232633
diff --git a/ldap/servers/slapd/schema.c b/ldap/servers/slapd/schema.c
232633
index 379fe208b..f609c220d 100644
232633
--- a/ldap/servers/slapd/schema.c
232633
+++ b/ldap/servers/slapd/schema.c
232633
@@ -2363,9 +2363,9 @@ schema_delete_attributes(Slapi_Entry *entryBefore __attribute__((unused)), LDAPM
232633
             attr_ldif[k] = tolower(attr_ldif[k]);
232633
         }
232633
 
232633
-        sizedbuffer_allocate(psbAttrName, strlen(attr_ldif));
232633
-        sizedbuffer_allocate(psbAttrOid, strlen(attr_ldif));
232633
-        sizedbuffer_allocate(psbAttrSyntax, strlen(attr_ldif));
232633
+        sizedbuffer_allocate(psbAttrName, strlen(attr_ldif) + 1);
232633
+        sizedbuffer_allocate(psbAttrOid, strlen(attr_ldif) + 1);
232633
+        sizedbuffer_allocate(psbAttrSyntax, strlen(attr_ldif) + 1);
232633
 
232633
         sscanf(attr_ldif, "%s name %s syntax %s",
232633
                psbAttrOid->buffer, psbAttrName->buffer, psbAttrSyntax->buffer);
232633
diff --git a/ldap/servers/slapd/search.c b/ldap/servers/slapd/search.c
232633
index 7e253f535..953227ba0 100644
232633
--- a/ldap/servers/slapd/search.c
232633
+++ b/ldap/servers/slapd/search.c
232633
@@ -37,7 +37,7 @@ do_search(Slapi_PBlock *pb)
232633
 {
232633
     Slapi_Operation *operation;
232633
     BerElement *ber;
232633
-    int i, err, attrsonly;
232633
+    int i, err = 0, attrsonly;
232633
     ber_int_t scope, deref, sizelimit, timelimit;
232633
     char *rawbase = NULL;
232633
     int rawbase_set_in_pb = 0; /* was rawbase set in pb? */
232633
@@ -232,6 +232,7 @@ do_search(Slapi_PBlock *pb)
232633
                     log_search_access(pb, base, scope, fstr, "invalid attribute request");
232633
                     send_ldap_result(pb, LDAP_PROTOCOL_ERROR, NULL, NULL, 0, NULL);
232633
                     slapi_ch_free_string(&normaci);
232633
+                    err = 1;  /* Make sure we free everything */
232633
                     goto free_and_return;
232633
                 }
232633
             }
232633
@@ -357,8 +358,8 @@ do_search(Slapi_PBlock *pb)
232633
         ps_add(pb, changetypes, send_entchg_controls);
232633
     }
232633
 
232633
-free_and_return:;
232633
-    if (!psearch || rc != 0) {
232633
+free_and_return:
232633
+    if (!psearch || rc != 0 || err != 0) {
232633
         slapi_ch_free_string(&fstr);
232633
         slapi_filter_free(filter, 1);
232633
         slapi_pblock_get(pb, SLAPI_SEARCH_ATTRS, &attrs);
232633
diff --git a/ldap/servers/slapd/tools/dbscan.c b/ldap/servers/slapd/tools/dbscan.c
232633
index 53cdb8985..c74d4823c 100644
232633
--- a/ldap/servers/slapd/tools/dbscan.c
232633
+++ b/ldap/servers/slapd/tools/dbscan.c
232633
@@ -532,7 +532,7 @@ print_changelog(unsigned char *data, int len __attribute__((unused)))
232633
     replgen = ntohl(thetime32);
232633
     pos += sizeof(uint32_t);
232633
     thetime = (time_t)replgen;
232633
-    db_printf("\treplgen: %ld %s", replgen, ctime((time_t *)&thetime));
232633
+    db_printf("\treplgen: %u %s", replgen, ctime((time_t *)&thetime));
232633
 
232633
     /* read csn */
232633
     print_attr("csn", &pos;;
232633
@@ -717,12 +717,15 @@ display_item(DBC *cursor, DBT *key, DBT *data)
232633
         tmpbuflen = (key->size > data->size ? key->size : data->size) + 1024;
232633
     }
232633
     if (buflen < tmpbuflen) {
232633
+        unsigned char *tmp = NULL;
232633
         buflen = tmpbuflen;
232633
-        buf = (unsigned char *)realloc(buf, buflen);
232633
-        if (NULL == buf) {
232633
+        tmp = (unsigned char *)realloc(buf, buflen);
232633
+        if (NULL == tmp) {
232633
+            free(buf);
232633
             printf("\t(malloc failed -- %d bytes)\n", buflen);
232633
             return;
232633
         }
232633
+        buf = tmp;
232633
     }
232633
 
232633
     if (display_mode & RAWDATA) {
232633
diff --git a/ldap/servers/slapd/tools/ldclt/ldapfct.c b/ldap/servers/slapd/tools/ldclt/ldapfct.c
232633
index 373076500..ca0912d6c 100644
232633
--- a/ldap/servers/slapd/tools/ldclt/ldapfct.c
232633
+++ b/ldap/servers/slapd/tools/ldclt/ldapfct.c
232633
@@ -986,9 +986,9 @@ buildVersatileAttribute(
232633
             break;
232633
         default:
232633
             /*
232633
-     * Should not happen, unless new variant parsed and not
232633
-     * integrated here, or "jardinage"....
232633
-     */
232633
+             * Should not happen, unless new variant parsed and not
232633
+             * integrated here, or "jardinage"....
232633
+             */
232633
             field = NULL;
232633
             field->how = 22; /* Crash !!! */
232633
             break;
232633
@@ -3231,7 +3231,7 @@ doExactSearch(
232633
                     case LDAP_RES_SEARCH_ENTRY:
232633
                         nentries++;
232633
                         /* get dereferenced value into resctrls:  deref parsing  */
232633
-                        parse_rc = ldap_get_entry_controls(tttctx->ldapCtx, e, &resctrls);
232633
+                        ldap_get_entry_controls(tttctx->ldapCtx, e, &resctrls);
232633
                         if (resctrls != NULL) { /* parse it only when we have return saved in server control */
232633
                             /* get dn */
232633
                             if ((dn = ldap_get_dn(tttctx->ldapCtx, e)) != NULL) {
232633
diff --git a/ldap/servers/slapd/tools/ldclt/ldclt.c b/ldap/servers/slapd/tools/ldclt/ldclt.c
232633
index e72b775e2..586a14713 100644
232633
--- a/ldap/servers/slapd/tools/ldclt/ldclt.c
232633
+++ b/ldap/servers/slapd/tools/ldclt/ldclt.c
232633
@@ -816,7 +816,7 @@ trapVector(
232633
 int
232633
 initMainThread(void)
232633
 {
232633
-    struct sigaction act;
232633
+    struct sigaction act = {0};
232633
 
232633
 /*
232633
    * Trap SIGINT.
232633
diff --git a/ldap/servers/slapd/tools/ldif.c b/ldap/servers/slapd/tools/ldif.c
232633
index 3548c7d49..a13e99f89 100644
232633
--- a/ldap/servers/slapd/tools/ldif.c
232633
+++ b/ldap/servers/slapd/tools/ldif.c
232633
@@ -92,11 +92,13 @@ main(int argc, char **argv)
232633
             }
232633
             if (nread + cur > max) {
232633
                 max += BUFSIZ;
232633
-                if ((val = (char *)realloc(val, max)) ==
232633
-                    NULL) {
232633
+                char *tmp = NULL;
232633
+                if ((tmp = (char *)realloc(val, max)) == NULL) {
232633
+                    free(val);
232633
                     perror("realloc");
232633
                     return (1);
232633
                 }
232633
+                val = tmp;
232633
             }
232633
             memcpy(val + cur, buf, nread);
232633
             cur += nread;
232633
@@ -125,12 +127,14 @@ main(int argc, char **argv)
232633
             /* if buffer was filled, expand and keep reading unless last char
232633
             is linefeed, in which case it is OK for buffer to be full */
232633
             while (((curlen = strlen(buf)) == (maxlen - 1)) && buf[curlen - 1] != '\n') {
232633
+                char *tmp = NULL;
232633
                 maxlen *= 2;
232633
-                if ((buf = (char *)realloc(buf, maxlen)) == NULL) {
232633
+                if ((tmp = (char *)realloc(buf, maxlen)) == NULL) {
232633
                     perror("realloc");
232633
                     free(buf);
232633
                     return (1);
232633
                 }
232633
+                buf = tmp;
232633
                 if (NULL == fgets(buf + curlen, maxlen / 2 + 1, stdin)) {
232633
                     /* no more input to read. */
232633
                     break;
232633
diff --git a/ldap/servers/slapd/tools/mmldif.c b/ldap/servers/slapd/tools/mmldif.c
232633
index cdcf4b16d..96b606a29 100644
232633
--- a/ldap/servers/slapd/tools/mmldif.c
232633
+++ b/ldap/servers/slapd/tools/mmldif.c
232633
@@ -700,7 +700,6 @@ readrec(edfFILE *edf1, attrib1_t **attrib)
232633
     attrib1_t *freelist = *attrib;
232633
     attrib1_t *newlist = NULL;
232633
     attrib1_t *a;
232633
-    int ignore_rec = FALSE;
232633
     int free_it = 0;
232633
 
232633
     *attrib = NULL;
232633
@@ -758,7 +757,7 @@ readrec(edfFILE *edf1, attrib1_t **attrib)
232633
         if (!stricmp(line, "authoritative"))
232633
             continue;
232633
         if (!freelist) {
232633
-            att = (attrib1_t *)malloc(sizeof(attrib1_t));
232633
+            att = (attrib1_t *)calloc(1, sizeof(struct attrib1_t *));
232633
             free_it = 1;
232633
         } else {
232633
             att = freelist;
232633
@@ -881,8 +880,6 @@ readrec(edfFILE *edf1, attrib1_t **attrib)
232633
     }
232633
     *attrib = newlist;
232633
     freefreelist(freelist);
232633
-    if (ignore_rec)
232633
-        return IDDS_MM_ABSENT;
232633
     return IDDS_MM_OK;
232633
 }
232633
 
232633
diff --git a/ldap/servers/slapd/tools/pwenc.c b/ldap/servers/slapd/tools/pwenc.c
232633
index d92e94e17..87ca17488 100644
232633
--- a/ldap/servers/slapd/tools/pwenc.c
232633
+++ b/ldap/servers/slapd/tools/pwenc.c
232633
@@ -362,6 +362,7 @@ slapd_config(const char *configdir, const char *givenconfigfile)
232633
                     }
232633
                 } else if (slapi_sdn_compare(&config_dn, slapi_entry_get_sdn_const(e)) == 0) {
232633
                     /* Get the root scheme out and initialise it (if it exists) */
232633
+                    slapi_ch_free_string(&rootschemename);
232633
                     rootschemename = slapi_entry_attr_get_charptr(e, CONFIG_ROOTPWSTORAGESCHEME_ATTRIBUTE);
232633
                 }
232633
 
232633
diff --git a/ldap/servers/slapd/tools/rsearch/infadd.c b/ldap/servers/slapd/tools/rsearch/infadd.c
232633
index db6fb23ae..6fe84f9e1 100644
232633
--- a/ldap/servers/slapd/tools/rsearch/infadd.c
232633
+++ b/ldap/servers/slapd/tools/rsearch/infadd.c
232633
@@ -309,7 +309,7 @@ main(int argc, char **argv)
232633
                         at_getThread(threads[x], NULL), min, max, count,
232633
                         ntot);
232633
         }
232633
-        if (!quiet && (numThreads > 1 || !verbose)) {
232633
+        if (numThreads > 1 && !quiet && !verbose) {
232633
             double val = 1000.0 * (double)total / (double)sampleInterval;
232633
             fprintf(stdout, "Rate: %7.2f/thr (%6.2f/sec =%7.4fms/op), "
232633
                             "total: %u (%d thr)\n",
232633
diff --git a/ldap/servers/slapd/tools/rsearch/rsearch.c b/ldap/servers/slapd/tools/rsearch/rsearch.c
232633
index 7602b16d8..347c84d2a 100644
232633
--- a/ldap/servers/slapd/tools/rsearch/rsearch.c
232633
+++ b/ldap/servers/slapd/tools/rsearch/rsearch.c
232633
@@ -467,7 +467,10 @@ main(int argc, char **argv)
232633
                 printf("T%d min=%4ums, max=%4ums, count = %u\n",
232633
                        st_getThread(threads[x], NULL), min, max, count);
232633
         }
232633
-        rate = (double)total / (double)numThreads;
232633
+        rate = 0.0;
232633
+        if (numThreads) {
232633
+            rate = (double)total / (double)numThreads;
232633
+        }
232633
         val = 1000.0 * (double)total / (double)sampleInterval;
232633
         cumrate += rate;
232633
         if ((numThreads > 1) || (!verbose)) {
232633
diff --git a/lib/ldaputil/certmap.c b/lib/ldaputil/certmap.c
232633
index efe531a51..dc2fdde43 100644
232633
--- a/lib/ldaputil/certmap.c
232633
+++ b/lib/ldaputil/certmap.c
232633
@@ -374,6 +374,7 @@ dbinfo_to_certinfo(DBConfDBInfo_t *db_info,
232633
             rv = ldapu_list_add_info(propval_list, propval);
232633
 
232633
             if (rv != LDAPU_SUCCESS) {
232633
+                ldapu_propval_free((void *)propval, (void *)propval);
232633
                 goto error;
232633
             }
232633
 
232633
@@ -700,15 +701,14 @@ certmap_read_certconfig_file(const char *file)
232633
         while (curdb) {
232633
             nextdb = curdb->next;
232633
             rv = dbinfo_to_certinfo(curdb, &certinfo);
232633
-
232633
             if (rv != LDAPU_SUCCESS) {
232633
                 dbconf_free_confinfo(conf_info);
232633
                 return rv;
232633
             }
232633
 
232633
             rv = process_certinfo(certinfo);
232633
-
232633
             if (rv != LDAPU_SUCCESS) {
232633
+                ldapu_certinfo_free(certinfo);
232633
                 dbconf_free_confinfo(conf_info);
232633
                 return rv;
232633
             }
232633
@@ -1330,8 +1330,11 @@ ldapu_cert_to_ldap_entry(void *cert, LDAP *ld, const char *basedn, LDAPMessage *
232633
 
232633
     rv = (*mapfn)(cert, ld, certmap_info, &ldapDN, &filter);
232633
 
232633
-    if (rv != LDAPU_SUCCESS)
232633
+    if (rv != LDAPU_SUCCESS) {
232633
+        free(ldapDN);
232633
+        free(filter);
232633
         return rv;
232633
+    }
232633
 
232633
     /* Get the search function from the certmap_info - certinfo maybe NULL */
232633
     searchfn = ldapu_get_cert_searchfn_sub(certmap_info);
232633
@@ -1339,10 +1342,8 @@ ldapu_cert_to_ldap_entry(void *cert, LDAP *ld, const char *basedn, LDAPMessage *
232633
     rv = (*searchfn)(cert, ld, certmap_info, basedn, ldapDN, filter,
232633
                      certmap_attrs, &res_array);
232633
 
232633
-    if (ldapDN)
232633
-        free(ldapDN);
232633
-    if (filter)
232633
-        free(filter);
232633
+    free(ldapDN);
232633
+    free(filter);
232633
 
232633
     /*
232633
      * Get the verify cert function & call it.
232633
diff --git a/lib/libaccess/usrcache.cpp b/lib/libaccess/usrcache.cpp
232633
index 5ea8259fe..b6ac58d3c 100644
232633
--- a/lib/libaccess/usrcache.cpp
232633
+++ b/lib/libaccess/usrcache.cpp
232633
@@ -157,11 +157,11 @@ int acl_usr_cache_init ()
232633
     }
232633
     else {
232633
 	singleDbTable = 0;
232633
-	databaseUserCacheTable = PR_NewHashTable(0, 
232633
+	databaseUserCacheTable = PR_NewHashTable(0,
232633
 						 PR_HashCaseString,
232633
 						 PR_CompareCaseStrings,
232633
 						 PR_CompareValues,
232633
-						 &ACLPermAllocOps, 
232633
+						 &ACLPermAllocOps,
232633
 						 usrcache_pool);
232633
     }
232633
 
232633
@@ -176,7 +176,7 @@ int acl_usr_cache_init ()
232633
     for(i = 0; i < num_usrobj; i++){
232633
 	usrobj = (UserCacheObj *)pool_malloc(usrcache_pool,
232633
 					     sizeof(UserCacheObj));
232633
-					     
232633
+
232633
 	if (!usrobj) return -1;
232633
 	memset((void *)usrobj, 0, sizeof(UserCacheObj));
232633
 	PR_INSERT_AFTER(&usrobj->list, usrobj_list);
232633
diff --git a/src/cockpit/389-console/src/lib/database/chaining.jsx b/src/cockpit/389-console/src/lib/database/chaining.jsx
232633
index 3dd3ec48e..c169e7bd3 100644
232633
--- a/src/cockpit/389-console/src/lib/database/chaining.jsx
232633
+++ b/src/cockpit/389-console/src/lib/database/chaining.jsx
232633
@@ -916,7 +916,7 @@ export class ChainingConfig extends React.Component {
232633
                 </Checkbox>;
232633
         } else {
232633
             proxiedAuth =
232633
-                
232633
+                
232633
                     title="Allow proxied authentication to the remote server. (nsproxiedauthorization).">
232633
                     Allow Proxied Authentication
232633
                 </Checkbox>;
232633
diff --git a/src/cockpit/389-console/src/lib/database/suffix.jsx b/src/cockpit/389-console/src/lib/database/suffix.jsx
232633
index 9cfb95b92..3f3bc82ec 100644
232633
--- a/src/cockpit/389-console/src/lib/database/suffix.jsx
232633
+++ b/src/cockpit/389-console/src/lib/database/suffix.jsx
232633
@@ -254,10 +254,10 @@ export class Suffix extends React.Component {
232633
         // Do import
232633
         let export_cmd = [
232633
             "dsconf", "-j", "ldapi://%2fvar%2frun%2fslapd-" + this.props.serverId + ".socket",
232633
-            "backend", "export", this.props.suffix, "--ldif=" + this.state.ldifLocation, "--encrypted"
232633
+            "backend", "export", this.props.suffix, "--ldif=" + this.state.ldifLocation
232633
         ];
232633
 
232633
-        if (this.state.attrEncrpytion) {
232633
+        if (this.state.attrEncryption) {
232633
             export_cmd.push("--encrypted");
232633
         }
232633
 
232633
diff --git a/src/cockpit/389-console/src/replication.js b/src/cockpit/389-console/src/replication.js
232633
index 6ef363523..2fe3a6e48 100644
232633
--- a/src/cockpit/389-console/src/replication.js
232633
+++ b/src/cockpit/389-console/src/replication.js
232633
@@ -1185,7 +1185,7 @@ $(document).ready( function() {
232633
         }
232633
       } else {
232633
         if ( !('nsds5replicatedattributelisttotal' in repl_agmt_values) ||
232633
-             agmt_tot_exclude != repl_agmt_values['nsds5replicatedattributelisttotal'].replace(frac_prefix, ""));
232633
+             agmt_tot_exclude != repl_agmt_values['nsds5replicatedattributelisttotal'].replace(frac_prefix, ""))
232633
         {
232633
           cmd_args.push('--frac-list-total=' + frac_prefix + ' ' + agmt_tot_exclude);
232633
         }
232633
diff --git a/src/lib389/lib389/agreement.py b/src/lib389/lib389/agreement.py
232633
index dcab900b8..84e2f8c61 100644
232633
--- a/src/lib389/lib389/agreement.py
232633
+++ b/src/lib389/lib389/agreement.py
232633
@@ -266,6 +266,7 @@ class Agreement(DSLdapObject):
232633
 
232633
         # Extract the csn timstamps and compare them
232633
         agmt_time = 0
232633
+        con_time = 0
232633
         match = Agreement.csnre.match(agmt_maxcsn)
232633
         if match:
232633
             agmt_time = int(match.group(1), 16)
232633
diff --git a/src/lib389/lib389/backend.py b/src/lib389/lib389/backend.py
232633
index 64a40c15a..353a3e117 100644
232633
--- a/src/lib389/lib389/backend.py
232633
+++ b/src/lib389/lib389/backend.py
232633
@@ -480,6 +480,9 @@ class Backend(DSLdapObject):
232633
         :returns: DSLdapObject of the created entry
232633
         """
232633
 
232633
+        sample_entries = False
232633
+        parent_suffix = False
232633
+
232633
         # normalize suffix (remove spaces between comps)
232633
         if dn is not None:
232633
             dn_comps = ldap.dn.explode_dn(dn.lower())
232633
@@ -490,9 +493,8 @@ class Backend(DSLdapObject):
232633
             dn_comps = ldap.dn.explode_dn(suffix_dn)
232633
             ndn = ",".join(dn_comps)
232633
             properties['nsslapd-suffix'] = ndn
232633
-
232633
-        sample_entries = properties.pop(BACKEND_SAMPLE_ENTRIES, False)
232633
-        parent_suffix = properties.pop('parent', False)
232633
+            sample_entries = properties.pop(BACKEND_SAMPLE_ENTRIES, False)
232633
+            parent_suffix = properties.pop('parent', False)
232633
 
232633
         # Okay, now try to make the backend.
232633
         super(Backend, self).create(dn, properties, basedn)
232633
diff --git a/src/lib389/lib389/cli_conf/backend.py b/src/lib389/lib389/cli_conf/backend.py
232633
index 77ce3ddec..36e32ec48 100644
232633
--- a/src/lib389/lib389/cli_conf/backend.py
232633
+++ b/src/lib389/lib389/cli_conf/backend.py
232633
@@ -422,7 +422,7 @@ def backend_set(inst, basedn, log, args):
232633
     if args.add_referral:
232633
         be.add('nsslapd-referral', args.add_referral)
232633
     if args.del_referral:
232633
-        be.remove('nsslapd-referral', args.add_referral)
232633
+        be.remove('nsslapd-referral', args.del_referral)
232633
     if args.cache_size:
232633
         be.set('nsslapd-cachesize', args.cache_size)
232633
     if args.cache_memsize:
232633
-- 
232633
2.21.0
232633