andykimpe / rpms / 389-ds-base

Forked from rpms/389-ds-base 5 months ago
Clone
Blob Blame History Raw
From 12552b47385b98ad294fdb1f229861998c83ec2f Mon Sep 17 00:00:00 2001
From: Mark Reynolds <mreynolds@redhat.com>
Date: Wed, 5 Jun 2013 16:19:57 -0400
Subject: [PATCH 92/99] Coverity Fixes (Part 4)

11753 - Resource leak (aclparse.c)
11754 - Resource leak (dna.c)
11755 - Resource leak (dna.c)
11756 - Resource leak (linked_attrs.c)
11757 - Resource leak (pam_ptconfig.c)
11758 - Resource leak (repl5_replica_config.c)
11759 - Resource leak (windows_inc_protocol.c)
11760 - Resource leak (syntaxes/value.c)
11761 - Resource leak (dblayer.c)
11764 - Resource leak (dblayer.c)
11766 - Resource leak (dblayer.c)
11769 - Resource leak (entry.c)
11770 - Resource leak (entry.c)
11773 - Resource leak (schema.c)
11774 - Resource leak (snmp_collator.c)
11775 - Resource leak (ldclt/data.c)
11776 - Resource leak (tools/mmldif.c)
11777 - Resource leak (snmp/main.c)
11778 - Resource leak (lib/libutil/dbconf.c)
11779 - Resource leak (lib/libaccess/register.cpp)
11781 - Resource leak (lib/libadmin/error.c)
11872 - Resource leak (agtmmap.c)

https://bugzilla.redhat.com/show_bug.cgi?id=970221

Reviewed by: nhosoi(Thanks!)
(cherry picked from commit 26127d5f7a96c33dfc46f3c8fc21de07455ea667)
(cherry picked from commit 3ab5aba6252798b895953a6f2af50916d3525ceb)
---
 ldap/servers/plugins/acl/acl.h                     |  1 +
 ldap/servers/plugins/acl/acllist.c                 |  7 +++---
 ldap/servers/plugins/acl/aclparse.c                | 29 +++++++++++-----------
 ldap/servers/plugins/dna/dna.c                     |  7 ++++++
 ldap/servers/plugins/linkedattrs/linked_attrs.c    |  7 ++++++
 ldap/servers/plugins/pam_passthru/pam_ptconfig.c   |  6 +++++
 .../plugins/replication/repl5_replica_config.c     |  3 +--
 .../plugins/replication/windows_inc_protocol.c     |  1 +
 ldap/servers/plugins/syntaxes/value.c              | 14 +++++++++++
 ldap/servers/slapd/agtmmap.c                       |  1 +
 ldap/servers/slapd/back-ldbm/dblayer.c             | 14 +++++++----
 ldap/servers/slapd/entry.c                         |  7 +++++-
 ldap/servers/slapd/schema.c                        |  6 +++--
 ldap/servers/slapd/snmp_collator.c                 |  4 ++-
 ldap/servers/slapd/tools/ldclt/data.c              |  2 ++
 ldap/servers/slapd/tools/mmldif.c                  |  6 +++++
 ldap/servers/snmp/main.c                           |  3 +++
 lib/ldaputil/dbconf.c                              |  7 ++++--
 lib/libaccess/register.cpp                         |  1 +
 lib/libadmin/error.c                               |  7 ++++--
 20 files changed, 99 insertions(+), 34 deletions(-)

diff --git a/ldap/servers/plugins/acl/acl.h b/ldap/servers/plugins/acl/acl.h
index e2b04c3..c61ee70 100644
--- a/ldap/servers/plugins/acl/acl.h
+++ b/ldap/servers/plugins/acl/acl.h
@@ -866,6 +866,7 @@ int			acllist_moddn_aci_needsLock ( Slapi_DN *oldsdn, char *newdn );
 void		acllist_print_tree ( Avlnode *root, int *depth, char *start, char *side);
 AciContainer *acllist_get_aciContainer_new ( );
 void 		acllist_done_aciContainer (  AciContainer *);
+void		free_targetattrfilters( Targetattrfilter ***attrFilterArray);
 
 aclUserGroup* aclg_find_userGroup (const char *n_dn);
 void 		aclg_regen_ugroup_signature( aclUserGroup *ugroup);
diff --git a/ldap/servers/plugins/acl/acllist.c b/ldap/servers/plugins/acl/acllist.c
index e8198af..623a739 100644
--- a/ldap/servers/plugins/acl/acllist.c
+++ b/ldap/servers/plugins/acl/acllist.c
@@ -94,7 +94,6 @@ static int		__acllist_add_aci ( aci_t *aci );
 static int		__acllist_aciContainer_node_cmp ( caddr_t d1, caddr_t d2 );
 static int		__acllist_aciContainer_node_dup ( caddr_t d1, caddr_t d2 );
 static void 	__acllist_free_aciContainer (  AciContainer **container);
-static void free_targetattrfilters( Targetattrfilter ***input_attrFilterArray);
 
 void my_print( Avlnode	*root );
 
@@ -565,8 +564,9 @@ acllist_free_aci(aci_t *item)
 	slapi_ch_free ( (void **) &item );
 }
 
-static void free_targetattrfilters( Targetattrfilter ***attrFilterArray) {    
-    
+void
+free_targetattrfilters( Targetattrfilter ***attrFilterArray)
+{
     if (*attrFilterArray) {
 		int			i = 0;
 		Targetattrfilter		*attrfilter;
@@ -592,7 +592,6 @@ static void free_targetattrfilters( Targetattrfilter ***attrFilterArray) {
 		/* Now free the array */
 		slapi_ch_free ( (void **) attrFilterArray );
 	}
-    
 }
 
 /* SEARCH */
diff --git a/ldap/servers/plugins/acl/aclparse.c b/ldap/servers/plugins/acl/aclparse.c
index 39d9f6c..8b11471 100644
--- a/ldap/servers/plugins/acl/aclparse.c
+++ b/ldap/servers/plugins/acl/aclparse.c
@@ -1935,14 +1935,13 @@ static int __acl__init_targetattrfilters( aci_t *aci, char *input_str) {
  * We need to put each component into a targetattrfilter component of
  * the array.
  *
-*/
-
+ */
 static int process_filter_list( Targetattrfilter ***input_attrFilterArray,
 						  char * input_str) {
 
 	char *str, *end_attr;
 	Targetattrfilter *attrfilter = NULL;
-	int		numattr=0;
+	int		numattr=0, rc = 0;
 	Targetattrfilter **attrFilterArray = NULL;
 
 	str = input_str;
@@ -1974,22 +1973,20 @@ static int process_filter_list( Targetattrfilter ***input_attrFilterArray,
 		memset (attrfilter, 0, sizeof(Targetattrfilter));
 
 		if (strstr( str,":") != NULL) {
-			
 			if ( __acl_init_targetattrfilter( attrfilter, str ) != 0 ) {
 				slapi_ch_free((void**)&attrfilter);
-				return(ACL_SYNTAX_ERR);
+				rc = ACL_SYNTAX_ERR;
+				break;
 			}        
 		} else {
 			slapi_ch_free((void**)&attrfilter);
-			return(ACL_SYNTAX_ERR);
+			rc = ACL_SYNTAX_ERR;
+			break;
 		}
 
-
 		/*
-		 * Add the attrfilte to the targetAttrFilter list
-		*/
-
-     	
+		 * Add the attrfilter to the targetAttrFilter list
+		 */
 		attrFilterArray = (Targetattrfilter **) slapi_ch_realloc (
 						    (void *) attrFilterArray,
 						    ((numattr+1)*sizeof(Targetattrfilter *)) ); 
@@ -1998,7 +1995,6 @@ static int process_filter_list( Targetattrfilter ***input_attrFilterArray,
 	
 		/* Move on to the next attribute in the list */
 		str = end_attr;
-
 	}/* while */
 
 	/* NULL terminate the list */
@@ -2007,10 +2003,13 @@ static int process_filter_list( Targetattrfilter ***input_attrFilterArray,
 						    (void *) attrFilterArray,
 						    ((numattr+1)*sizeof(Targetattrfilter *)) ); 
 	attrFilterArray[numattr] = NULL;
+	if(rc){
+		free_targetattrfilters(&attrFilterArray);
+	} else {
+		*input_attrFilterArray = attrFilterArray;
+	}
 
-	*input_attrFilterArray = attrFilterArray;
-	return 0;
-
+	return rc;
 }
 
 /*
diff --git a/ldap/servers/plugins/dna/dna.c b/ldap/servers/plugins/dna/dna.c
index d3dfa52..958a4a7 100644
--- a/ldap/servers/plugins/dna/dna.c
+++ b/ldap/servers/plugins/dna/dna.c
@@ -1515,11 +1515,13 @@ dna_get_shared_servers(struct configEntry *config_entry, PRCList **servers)
                      * to lowest. */
                     struct dnaServer *sitem;
                     PRCList* item = PR_LIST_HEAD(*servers);
+                    int inserted = 0;
 
                     while (item != *servers) {
                         sitem = (struct dnaServer *)item;
                         if (server->remaining > sitem->remaining) {
                             PR_INSERT_BEFORE(&(server->list), item);
+                            inserted = 1;
                             break;
                         }
 
@@ -1528,9 +1530,13 @@ dna_get_shared_servers(struct configEntry *config_entry, PRCList **servers)
                         if (*servers == item) {
                             /* add to tail */
                             PR_INSERT_BEFORE(&(server->list), item);
+                            inserted = 1;
                             break;
                         }
                     }
+                    if(!inserted){
+                    	dna_free_shared_server(&server);
+                    }
                 }
             }
         }
@@ -3340,6 +3346,7 @@ dna_pre_op(Slapi_PBlock * pb, int modtype)
 bail:
     if (resulting_e)
         slapi_entry_free(resulting_e);
+    slapi_mods_free(&smods);
 
     if (ret) {
         slapi_log_error(SLAPI_LOG_PLUGIN, DNA_PLUGIN_SUBSYSTEM,
diff --git a/ldap/servers/plugins/linkedattrs/linked_attrs.c b/ldap/servers/plugins/linkedattrs/linked_attrs.c
index 4bea10f..7d8370d 100644
--- a/ldap/servers/plugins/linkedattrs/linked_attrs.c
+++ b/ldap/servers/plugins/linkedattrs/linked_attrs.c
@@ -755,6 +755,7 @@ linked_attrs_insert_config_index(struct configEntry *entry)
     struct configEntry *config_entry = NULL;
     struct configIndex *index_entry = NULL;
     PRCList *list = PR_LIST_HEAD(g_managed_config_index);
+    int inserted = 0;
 
     index_entry = (struct configIndex *)slapi_ch_calloc(1, sizeof(struct configIndex));
     index_entry->config = entry;
@@ -769,6 +770,7 @@ linked_attrs_insert_config_index(struct configEntry *entry)
                 slapi_log_error(SLAPI_LOG_CONFIG, LINK_PLUGIN_SUBSYSTEM,
                                 "store [%s] before [%s] \n", entry->dn,
                                 config_entry->dn);
+                inserted = 1;
                 break;
             }
     
@@ -779,6 +781,7 @@ linked_attrs_insert_config_index(struct configEntry *entry)
                 PR_INSERT_BEFORE(&(index_entry->list), list);
                 slapi_log_error(SLAPI_LOG_CONFIG, LINK_PLUGIN_SUBSYSTEM,
                                 "store [%s] at tail\n", entry->dn);
+                inserted = 1;
                 break;
             }
         }
@@ -787,6 +790,10 @@ linked_attrs_insert_config_index(struct configEntry *entry)
         slapi_log_error(SLAPI_LOG_CONFIG, LINK_PLUGIN_SUBSYSTEM,
                         "store [%s] at head \n", entry->dn);
         PR_INSERT_LINK(&(index_entry->list), g_managed_config_index);
+        inserted = 1;
+    }
+    if(!inserted){
+    	slapi_ch_free((void **)&index_entry);
     }
 }
 
diff --git a/ldap/servers/plugins/pam_passthru/pam_ptconfig.c b/ldap/servers/plugins/pam_passthru/pam_ptconfig.c
index fce8000..9391891 100644
--- a/ldap/servers/plugins/pam_passthru/pam_ptconfig.c
+++ b/ldap/servers/plugins/pam_passthru/pam_ptconfig.c
@@ -603,6 +603,7 @@ pam_passthru_apply_config (Slapi_Entry* e)
     PRCList *list;
     Slapi_Attr *a = NULL;
     char *filter_str = NULL;
+    int inserted = 0;
 
     pam_ident_attr = slapi_entry_attr_get_charptr(e, PAMPT_PAM_IDENT_ATTR);
     map_method = slapi_entry_attr_get_charptr(e, PAMPT_MAP_METHOD_ATTR);
@@ -689,6 +690,7 @@ pam_passthru_apply_config (Slapi_Entry* e)
                 PR_INSERT_BEFORE(&(entry->list), list);
                 slapi_log_error(SLAPI_LOG_CONFIG, PAM_PASSTHRU_PLUGIN_SUBSYSTEM,
                                 "store [%s] at tail\n", entry->dn);
+                inserted = 1;
                 break;
             }
         }
@@ -697,9 +699,13 @@ pam_passthru_apply_config (Slapi_Entry* e)
         PR_INSERT_LINK(&(entry->list), pam_passthru_global_config);
         slapi_log_error(SLAPI_LOG_CONFIG, PAM_PASSTHRU_PLUGIN_SUBSYSTEM,
                         "store [%s] at head \n", entry->dn);
+        inserted = 1;
     }
 
   bail:
+    if(!inserted){
+    	pam_passthru_free_config_entry(&entry);
+    }
     slapi_ch_free_string(&new_service);
     slapi_ch_free_string(&map_method);
     slapi_ch_free_string(&pam_ident_attr);
diff --git a/ldap/servers/plugins/replication/repl5_replica_config.c b/ldap/servers/plugins/replication/repl5_replica_config.c
index 7b684e9..5ca7706 100644
--- a/ldap/servers/plugins/replication/repl5_replica_config.c
+++ b/ldap/servers/plugins/replication/repl5_replica_config.c
@@ -1745,7 +1745,7 @@ check_replicas_are_done_cleaning(cleanruv_data *data )
 {
     Object *agmt_obj;
     Repl_Agmt *agmt;
-    char *csnstr = NULL;
+    char csnstr[CSN_STRSIZE];
     char *filter = NULL;
     int not_all_cleaned = 1;
     int interval = 10;
@@ -1788,7 +1788,6 @@ check_replicas_are_done_cleaning(cleanruv_data *data )
             interval = 14400;
         }
     }
-    slapi_ch_free_string(&csnstr);
     slapi_ch_free_string(&filter);
 }
 
diff --git a/ldap/servers/plugins/replication/windows_inc_protocol.c b/ldap/servers/plugins/replication/windows_inc_protocol.c
index cb3b3d2..15d69a3 100644
--- a/ldap/servers/plugins/replication/windows_inc_protocol.c
+++ b/ldap/servers/plugins/replication/windows_inc_protocol.c
@@ -1026,6 +1026,7 @@ windows_inc_run(Private_Repl_Protocol *prp)
   windows_conn_cancel_linger(prp->conn);
   /* ... and disconnect, if currently connected */
   windows_conn_disconnect(prp->conn);
+  ruv_destroy ( &ruv );
   LDAPDebug0Args( LDAP_DEBUG_TRACE, "<= windows_inc_run\n" );
 }
 
diff --git a/ldap/servers/plugins/syntaxes/value.c b/ldap/servers/plugins/syntaxes/value.c
index efef9a8..0335a89 100644
--- a/ldap/servers/plugins/syntaxes/value.c
+++ b/ldap/servers/plugins/syntaxes/value.c
@@ -282,10 +282,13 @@ value_cmp(
 		value_normalize_ext( v1->bv_val, syntax, 
 							 1 /* trim leading blanks */, &alt );
 		if (alt) {
+			int inserted = 0;
+
 			if (free_v1) {
 				slapi_ch_free_string(&v1->bv_val);
 				v1->bv_val = alt;
 				v1->bv_len = strlen(alt);
+				inserted = 1;
 			} else {
 				if (strlen(alt) < buffer_space) {
 					v1->bv_len = strlen(alt);
@@ -297,8 +300,12 @@ value_cmp(
 					v1 = (struct berval *)slapi_ch_malloc(sizeof(struct berval));
 					v1->bv_val = alt;
 					v1->bv_len = strlen(alt);
+					inserted = 1;
 				}
 			}
+			if(!inserted){
+				slapi_ch_free_string(&alt);
+			}
 		}
 		if (!free_v1) {
 			buffer_space -= v1->bv_len + 1;
@@ -320,10 +327,13 @@ value_cmp(
 		value_normalize_ext( v2->bv_val, syntax, 
 							 1 /* trim leading blanks */, &alt );
 		if (alt) {
+			int inserted = 0;
+
 			if (free_v2) {
 				slapi_ch_free_string(&v2->bv_val);
 				v2->bv_val = alt;
 				v2->bv_len = strlen(alt);
+				inserted = 1;
 			} else {
 				if (strlen(alt) < buffer_space) {
 					v2->bv_len = strlen(alt);
@@ -335,8 +345,12 @@ value_cmp(
 					v2 = (struct berval *)slapi_ch_malloc(sizeof(struct berval));
 					v2->bv_val = alt;
 					v2->bv_len = strlen(alt);
+					inserted = 1;
 				}
 			}
+			if(!inserted){
+				slapi_ch_free_string(&alt);
+			}
 		}
 		if (!free_v2) {
 			buffer_space -= v2->bv_len + 1;
diff --git a/ldap/servers/slapd/agtmmap.c b/ldap/servers/slapd/agtmmap.c
index f18138a..3922547 100644
--- a/ldap/servers/slapd/agtmmap.c
+++ b/ldap/servers/slapd/agtmmap.c
@@ -196,6 +196,7 @@ agt_mopen_stats (char * statsfile, int mode, int *hdl)
                }
 		
                if(fstat (fd, &fileinfo) != 0){
+                   close(fd);
                    rc = errno;
                    goto bail;
 		       }
diff --git a/ldap/servers/slapd/back-ldbm/dblayer.c b/ldap/servers/slapd/back-ldbm/dblayer.c
index 960d99e..cb8ef68 100644
--- a/ldap/servers/slapd/back-ldbm/dblayer.c
+++ b/ldap/servers/slapd/back-ldbm/dblayer.c
@@ -1897,9 +1897,9 @@ dblayer_get_id2entry_size(ldbm_instance *inst)
 {
     struct ldbminfo *li = NULL;
     char *id2entry_file = NULL;
-    PRFileInfo info;
+    PRFileInfo64 info;
     int rc;
-    char inst_dir[MAXPATHLEN], *inst_dirp;
+    char inst_dir[MAXPATHLEN], *inst_dirp = NULL;
 
     if (NULL == inst) {
         return 0;
@@ -1908,7 +1908,10 @@ dblayer_get_id2entry_size(ldbm_instance *inst)
     inst_dirp = dblayer_get_full_inst_dir(li, inst, inst_dir, MAXPATHLEN);
     id2entry_file = slapi_ch_smprintf("%s/%s", inst_dirp,
                                       ID2ENTRY LDBM_FILENAME_SUFFIX);
-    rc = PR_GetFileInfo(id2entry_file, &info);
+    if(inst_dirp != inst_dir){
+        slapi_ch_free_string(&inst_dirp);
+    }
+    rc = PR_GetFileInfo64(id2entry_file, &info);
     slapi_ch_free_string(&id2entry_file);
     if (inst_dirp != inst_dir)
         slapi_ch_free_string(&inst_dirp);
@@ -3069,6 +3072,9 @@ dblayer_open_file(backend *be, char* indexname, int open_flag,
         }
         abs_file_name = slapi_ch_smprintf("%s%c%s",
                 inst_dirp, get_sep(inst_dirp), file_name);
+        if (inst_dirp != inst_dir){
+            slapi_ch_free_string(&inst_dirp);
+        }
         DB_OPEN(pENV->dblayer_openflags,
                 dbp, NULL/* txnid */, abs_file_name, subname, DB_BTREE,
                 open_flags, priv->dblayer_file_mode, return_value);
@@ -3084,8 +3090,6 @@ dblayer_open_file(backend *be, char* indexname, int open_flag,
             goto out;
 
         slapi_ch_free_string(&abs_file_name);
-        if (inst_dirp != inst_dir)
-            slapi_ch_free_string(&inst_dirp);
     }
     DB_OPEN(pENV->dblayer_openflags,
             dbp, NULL, /* txnid */ rel_path, subname, DB_BTREE,
diff --git a/ldap/servers/slapd/entry.c b/ldap/servers/slapd/entry.c
index f38c39e..a43dc21 100644
--- a/ldap/servers/slapd/entry.c
+++ b/ldap/servers/slapd/entry.c
@@ -552,6 +552,7 @@ str2entry_fast( const char *rawdn, char *s, int flags, int read_stateinfo )
 	}
 
 done:
+	csnset_free(&valuecsnset);
 	csn_free(&attributedeletioncsn);
 	csn_free(&maxcsn);
 	LDAPDebug( LDAP_DEBUG_TRACE, "<= str2entry_fast 0x%x\n",
@@ -744,6 +745,7 @@ str2entry_dupcheck( const char *rawdn, char *s, int flags, int read_stateinfo )
 			( 0 != ( flags & SLAPI_STR2ENTRY_REMOVEDUPVALS ));
 	Slapi_Value *value = 0;
 	CSN *attributedeletioncsn= NULL;
+	CSNSet *valuecsnset= NULL;
 	CSN *maxcsn= NULL;
 	char *normdn = NULL;
 	int strict = 0;
@@ -764,7 +766,6 @@ str2entry_dupcheck( const char *rawdn, char *s, int flags, int read_stateinfo )
 	}
     while ( (s = ldif_getline( &next )) != NULL )
     {
-		CSNSet *valuecsnset= NULL;
 		int value_state= VALUE_NOTFOUND;
 		int attr_state= VALUE_NOTFOUND;
 		int freeval = 0;
@@ -819,6 +820,7 @@ str2entry_dupcheck( const char *rawdn, char *s, int flags, int read_stateinfo )
 						    "str2entry_dupcheck: Invalid DN: %s\n", rawdn);
 						slapi_entry_free( e );
 						if (freeval) slapi_ch_free_string(&bvvalue.bv_val);
+						csnset_free(&valuecsnset);
 						csn_free(&attributedeletioncsn);
 						csn_free(&maxcsn);
 						return NULL;
@@ -841,6 +843,7 @@ str2entry_dupcheck( const char *rawdn, char *s, int flags, int read_stateinfo )
 							     "str2entry_dupcheck: Invalid DN: %s\n", rawdn);
 							slapi_entry_free( e );
 							if (freeval) slapi_ch_free_string(&bvvalue.bv_val);
+							csnset_free(&valuecsnset);
 							csn_free(&attributedeletioncsn);
 							csn_free(&maxcsn);
 							return NULL;
@@ -954,6 +957,7 @@ str2entry_dupcheck( const char *rawdn, char *s, int flags, int read_stateinfo )
 						if (freeval) slapi_ch_free_string(&bvvalue.bv_val);
 						csn_free(&attributedeletioncsn);
 						csn_free(&maxcsn);
+						csnset_free(&valuecsnset);
 						return NULL;
 					}
 					for ( i = 0; i < nattrs; i++ )
@@ -1285,6 +1289,7 @@ free_and_return:
 	}
 	slapi_ch_free((void **) &dyn_attrs );
 	if (value) slapi_value_free(&value);
+	csnset_free(&valuecsnset);
 	csn_free(&attributedeletioncsn);
 	csn_free(&maxcsn);
 
diff --git a/ldap/servers/slapd/schema.c b/ldap/servers/slapd/schema.c
index 1768c7e..258f6eb 100644
--- a/ldap/servers/slapd/schema.c
+++ b/ldap/servers/slapd/schema.c
@@ -3083,11 +3083,11 @@ read_oc_ldif ( const char *input, struct objclass **oc, char *errorbuf,
   pnew_oc->oc_kind = kind;
 
   *oc = pnew_oc;
+
   return read_oc_ldif_return( LDAP_SUCCESS, pOcOid, psbOcName, pOcSup,
 			oc_origins, num_origins, pOcDesc );
 }
 
-
 static void
 oc_free( struct objclass **ocp )
 {
@@ -3969,7 +3969,9 @@ load_schema_dse(Slapi_PBlock *pb, Slapi_Entry *e, Slapi_Entry *ignored,
             if ( LDAP_SUCCESS != (*returncode = read_oc_ldif(s, &oc, returntext,
                         SLAPI_DSE_RETURNTEXT_SIZE, flags,
                         primary_file /* force user defined? */,
-                        schema_ds4x_compat))) {
+                        schema_ds4x_compat)))
+            {
+            	oc_free( &oc );
                 break;
             }
             if (flags & DSE_SCHEMA_NO_LOAD)
diff --git a/ldap/servers/slapd/snmp_collator.c b/ldap/servers/slapd/snmp_collator.c
index aeac7ae..b3d072a 100644
--- a/ldap/servers/slapd/snmp_collator.c
+++ b/ldap/servers/slapd/snmp_collator.c
@@ -738,8 +738,10 @@ snmp_update_cache_stats()
 
     /* set the cache hits/cache entries info */
     be = slapi_get_first_backend(&cookie);
-    if (!be)
+    if (!be){
+    	slapi_ch_free ((void **) &cookie);
         return;
+    }
 
     be_next = slapi_get_next_backend(cookie);
 
diff --git a/ldap/servers/slapd/tools/ldclt/data.c b/ldap/servers/slapd/tools/ldclt/data.c
index e0eac55..f6dd4ef 100644
--- a/ldap/servers/slapd/tools/ldclt/data.c
+++ b/ldap/servers/slapd/tools/ldclt/data.c
@@ -335,6 +335,8 @@ exit:
 #ifdef _WIN32
   if (findPath) free (findPath);
 #endif
+  close(fd);
+
   return rc;
 }
 
diff --git a/ldap/servers/slapd/tools/mmldif.c b/ldap/servers/slapd/tools/mmldif.c
index 6d62338..fb97129 100644
--- a/ldap/servers/slapd/tools/mmldif.c
+++ b/ldap/servers/slapd/tools/mmldif.c
@@ -735,6 +735,7 @@ readrec(edfFILE * edf1, attrib1_t ** attrib)
     attrib1_t *	newlist = NULL;
     attrib1_t *	a;
     int		ignore_rec = FALSE;
+    int free_it = 0;
 
     *attrib = NULL;
     if (edf1->end) {
@@ -759,6 +760,9 @@ readrec(edfFILE * edf1, attrib1_t ** attrib)
                 /* that's for the case where the file */
                 /* has a trailing blank line */
                 freefreelist(freelist);
+                if(free_it){
+                	freefreelist(att);
+                }
                 return IDDS_MM_EOF;
             }
             break; /* return */
@@ -790,9 +794,11 @@ readrec(edfFILE * edf1, attrib1_t ** attrib)
             continue;
         if (!freelist) {
             att = (attrib1_t *)malloc(sizeof(attrib1_t));
+            free_it = 1;
         } else {
             att = freelist;
             freelist = freelist->next;
+            free_it = 0;
         }
         att->namelen = vptr-line;
 		
diff --git a/ldap/servers/snmp/main.c b/ldap/servers/snmp/main.c
index 0d1fb25..78d4814 100644
--- a/ldap/servers/snmp/main.c
+++ b/ldap/servers/snmp/main.c
@@ -322,6 +322,9 @@ load_config(char *conf_path)
             /* load agentx-master setting */
             p = p + 13;
             if ((p = strtok(p, " \t\n")) != NULL) {
+                if (agentx_master){
+                    free(agentx_master);
+                }
                 if ((agentx_master = (char *) malloc(strlen(p) + 1)) != NULL)
                     strcpy(agentx_master, p);
             }
diff --git a/lib/ldaputil/dbconf.c b/lib/ldaputil/dbconf.c
index 746afc9..e6de3b7 100644
--- a/lib/ldaputil/dbconf.c
+++ b/lib/ldaputil/dbconf.c
@@ -263,7 +263,10 @@ static int dbconf_parse_propval (char *buf, char *ptr,
     /* Success - we have prop & val */
     propval = (DBPropVal_t *)malloc(sizeof(DBPropVal_t));
 
-    if (!propval) return LDAPU_ERR_OUT_OF_MEMORY;
+    if (!propval){
+    	if (encval) free(val);
+        return LDAPU_ERR_OUT_OF_MEMORY;
+    }
     memset((void *)propval, 0, sizeof(DBPropVal_t));
     propval->prop = strdup(prop);
     propval->val = val ? strdup(val) : 0;
@@ -273,7 +276,7 @@ static int dbconf_parse_propval (char *buf, char *ptr,
 	return LDAPU_ERR_OUT_OF_MEMORY;
     }
 
-    if (encval) free(val);	/* val was allocated by dbconf_decodeval */
+    if(encval) free(val);	/* val was allocated by dbconf_decodeval */
 
     insert_dbinfo_propval(db_info, propval);
     return LDAPU_SUCCESS;
diff --git a/lib/libaccess/register.cpp b/lib/libaccess/register.cpp
index 595c1f2..798a926 100644
--- a/lib/libaccess/register.cpp
+++ b/lib/libaccess/register.cpp
@@ -793,6 +793,7 @@ ACL_AttrGetterRegister(NSErr_t *errp, const char *attr, ACLAttrGetterFn_t fn,
     if (*hep == 0) {	/* New entry */
         PR_INIT_CLIST(&getter->list);
         if (NULL == PR_HashTableAdd(ACLAttrGetterHash, attr, (void *)getter)) {
+            FREE(getter);
             ACL_CritExit();
             return -1;
         }
diff --git a/lib/libadmin/error.c b/lib/libadmin/error.c
index c0a1f80..4ba9803 100644
--- a/lib/libadmin/error.c
+++ b/lib/libadmin/error.c
@@ -126,10 +126,13 @@ NSAPI_PUBLIC void output_alert(int type, char *info, char *details, int wait)
     fprintf(stdout, "%s:%s\\n%s", error_headers[type], info, wrapped);
     if(type==FILE_ERROR || type==SYSTEM_ERROR)  {
         err = get_error();
-        if(err != 0)
+        if(err != 0){
+            char *err_str = verbose_error();
             fprintf(stdout,
                         "\\n\\nThe system returned error number %d, "
-                        "which is %s.", err, verbose_error());
+                        "which is %s.", err, err_str);
+            FREE(err_str);
+        }
     }
     fprintf(stdout, "\");");
 
-- 
1.8.1.4