andykimpe / rpms / 389-ds-base

Forked from rpms/389-ds-base 5 months ago
Clone
dc8c34
From 78798c93a7006f00681a6b34a082aaf756f0c208 Mon Sep 17 00:00:00 2001
dc8c34
From: Mark Reynolds <mreynolds@redhat.com>
dc8c34
Date: Wed, 12 Mar 2014 16:58:32 -0400
dc8c34
Subject: [PATCH 183/225] Ticket 47740 - Fix coverity erorrs - Part 4
dc8c34
dc8c34
12498 - resource leak - /ldap/servers/plugins/chainingdn/cb_instance.c
dc8c34
12490 - resource leak - /ldap/servers/plugins/chainingdn/cb_controls.c
dc8c34
12489 - resource leak - /ldap/servers/plugins/replication/repl5_replica_config.c
dc8c34
12488 - resource leak - /ldap/servers/slapd/main.c
dc8c34
12485 - resource leak - /ldap/servers/plugins/replication/repl5_replica_config.c
dc8c34
12484 - resource leak - /ldap/servers/plugins/replication/repl5_replica_config.c
dc8c34
12483 - resource leak - /ldap/servers/slapd/back-ldbm/upgrade.c
dc8c34
12482 - resource leak - /ldap/servers/plugins/replication/repl5_replica.c
dc8c34
12481 - resource leak - /ldap/servers/plugins/acl/aclplugin.c
dc8c34
12476 - resource leak - /ldap/servers/slapd/back-ldbm/upgrade.c
dc8c34
12475 - resource leak - /ldap/servers/slapd/back-ldbm/upgrade.c
dc8c34
dc8c34
https://fedorahosted.org/389/ticket/47740
dc8c34
dc8c34
Reviewed by: nhosoi(Thanks!)
dc8c34
(cherry picked from commit 85d062b3468663691188d22f58edb2a448e5e447)
dc8c34
---
dc8c34
 ldap/servers/plugins/acl/aclplugin.c                   |  8 +++-----
dc8c34
 ldap/servers/plugins/chainingdb/cb_controls.c          | 14 ++++++++------
dc8c34
 ldap/servers/plugins/chainingdb/cb_instance.c          | 18 +++++++++---------
dc8c34
 ldap/servers/plugins/replication/repl5_replica.c       |  3 ++-
dc8c34
 .../servers/plugins/replication/repl5_replica_config.c | 13 +++++++++----
dc8c34
 ldap/servers/slapd/back-ldbm/upgrade.c                 |  3 +++
dc8c34
 ldap/servers/slapd/main.c                              |  5 +++--
dc8c34
 ldap/servers/slapd/proxyauth.c                         | 12 ++++++------
dc8c34
 8 files changed, 43 insertions(+), 33 deletions(-)
dc8c34
dc8c34
diff --git a/ldap/servers/plugins/acl/aclplugin.c b/ldap/servers/plugins/acl/aclplugin.c
dc8c34
index 0d35425..5250e0d 100644
dc8c34
--- a/ldap/servers/plugins/acl/aclplugin.c
dc8c34
+++ b/ldap/servers/plugins/acl/aclplugin.c
dc8c34
@@ -197,7 +197,7 @@ aclplugin_preop_modify ( Slapi_PBlock *pb )
dc8c34
 int
dc8c34
 aclplugin_preop_common( Slapi_PBlock *pb )
dc8c34
 {
dc8c34
-	char		*proxy_dn;	/* id being assumed */
dc8c34
+	char		*proxy_dn = NULL;	/* id being assumed */
dc8c34
 	char		*dn;		/* proxy master */
dc8c34
 	char		*errtext = NULL;
dc8c34
 	int			lderr;
dc8c34
@@ -221,9 +221,7 @@ aclplugin_preop_common( Slapi_PBlock *pb )
dc8c34
 	 * The proxy_dn is the id being assumed, while dn
dc8c34
 	 * is the "proxy master".
dc8c34
 	*/
dc8c34
-	proxy_dn = NULL;
dc8c34
-	if ( LDAP_SUCCESS != ( lderr = proxyauth_get_dn( pb, &proxy_dn,
dc8c34
-			&errtext ))) {
dc8c34
+	if ( LDAP_SUCCESS != ( lderr = proxyauth_get_dn( pb, &proxy_dn, &errtext ))) {
dc8c34
 		/*
dc8c34
 		 * Fatal error -- send a result to the client and arrange to skip
dc8c34
 		 * any further processing.
dc8c34
@@ -231,7 +229,7 @@ aclplugin_preop_common( Slapi_PBlock *pb )
dc8c34
 		slapi_send_ldap_result( pb, lderr, NULL, errtext, 0, NULL );
dc8c34
 		TNF_PROBE_1_DEBUG(aclplugin_preop_common_end ,"ACL","",
dc8c34
 						tnf_string,proxid_error,"");
dc8c34
-
dc8c34
+		slapi_ch_free_string(&proxy_dn);
dc8c34
 		return 1;	/* skip any further processing */
dc8c34
 	}
dc8c34
 	slapi_pblock_get ( pb, SLAPI_REQUESTOR_DN, &dn );
dc8c34
diff --git a/ldap/servers/plugins/chainingdb/cb_controls.c b/ldap/servers/plugins/chainingdb/cb_controls.c
dc8c34
index 2a698a0..e1fc9c3 100644
dc8c34
--- a/ldap/servers/plugins/chainingdb/cb_controls.c
dc8c34
+++ b/ldap/servers/plugins/chainingdb/cb_controls.c
dc8c34
@@ -200,20 +200,22 @@ int cb_update_controls( Slapi_PBlock * pb,
dc8c34
                 char * requestor,*rootdn;
dc8c34
                 char * requestorCopy=NULL;
dc8c34
 
dc8c34
-                rootdn=cb_get_rootdn();
dc8c34
+                rootdn = cb_get_rootdn();
dc8c34
                 slapi_pblock_get( pb, SLAPI_REQUESTOR_NDN, &requestor );
dc8c34
                 requestorCopy = slapi_ch_strdup(requestor);
dc8c34
                 slapi_dn_ignore_case(requestorCopy);
dc8c34
 
dc8c34
                 if (!strcmp( requestorCopy, rootdn )) {    /* UTF8- aware */
dc8c34
                     slapi_log_error( SLAPI_LOG_PLUGIN,CB_PLUGIN_SUBSYSTEM,
dc8c34
-                    "Use of user <%s> incompatible with proxied auth. control\n",rootdn);
dc8c34
-                    rc=LDAP_UNAVAILABLE_CRITICAL_EXTENSION;
dc8c34
-                    slapi_ch_free((void **)&requestorCopy);
dc8c34
+                            "Use of user <%s> incompatible with proxied auth. control\n",
dc8c34
+                            rootdn);
dc8c34
+                    rc = LDAP_UNAVAILABLE_CRITICAL_EXTENSION;
dc8c34
+                    slapi_ch_free_string(&rootdn);
dc8c34
+                    slapi_ch_free_string(&requestorCopy);
dc8c34
                     break;
dc8c34
                 }
dc8c34
-                slapi_ch_free((void **)&rootdn);
dc8c34
-                slapi_ch_free((void **)&requestorCopy);
dc8c34
+                slapi_ch_free_string(&rootdn);
dc8c34
+                slapi_ch_free_string(&requestorCopy);
dc8c34
             }
dc8c34
 
dc8c34
             addauth=0;
dc8c34
diff --git a/ldap/servers/plugins/chainingdb/cb_instance.c b/ldap/servers/plugins/chainingdb/cb_instance.c
dc8c34
index ce7675b..86bb635 100644
dc8c34
--- a/ldap/servers/plugins/chainingdb/cb_instance.c
dc8c34
+++ b/ldap/servers/plugins/chainingdb/cb_instance.c
dc8c34
@@ -738,11 +738,11 @@ static int cb_instance_hosturl_set(void *arg, void *value, char *errorbuf, int p
dc8c34
 
dc8c34
 	if ((LDAP_SUCCESS == rc) && apply) {
dc8c34
 
dc8c34
-               	slapi_rwlock_wrlock(inst->rwl_config_lock);
dc8c34
-
dc8c34
-	        if (( phase != CB_CONFIG_PHASE_INITIALIZATION ) &&
dc8c34
-       			( phase != CB_CONFIG_PHASE_STARTUP )) {
dc8c34
+		slapi_rwlock_wrlock(inst->rwl_config_lock);
dc8c34
 
dc8c34
+		if (( phase != CB_CONFIG_PHASE_INITIALIZATION ) &&
dc8c34
+			( phase != CB_CONFIG_PHASE_STARTUP ))
dc8c34
+		{
dc8c34
 			/* Dynamic modification				*/
dc8c34
 			/* Don't free char * pointer now		*/
dc8c34
 			/* STore them in a waste basket 		*/
dc8c34
@@ -766,17 +766,17 @@ static int cb_instance_hosturl_set(void *arg, void *value, char *errorbuf, int p
dc8c34
 		/* the url and update the configuration  */
dc8c34
 
dc8c34
 		if ((ludp->lud_host==NULL) || (strlen(ludp->lud_host)==0)) {
dc8c34
-                        inst->pool->hostname=(char *)slapi_ch_strdup((char *)get_localhost_DNS());
dc8c34
+			inst->pool->hostname = get_localhost_DNS();
dc8c34
 		} else {
dc8c34
-               		inst->pool->hostname = slapi_ch_strdup( ludp->lud_host );
dc8c34
+			inst->pool->hostname = slapi_ch_strdup( ludp->lud_host );
dc8c34
 		}
dc8c34
-               	inst->pool->url = slapi_ch_strdup( url);
dc8c34
-               	inst->pool->secure = secure;
dc8c34
+		inst->pool->url = slapi_ch_strdup( url);
dc8c34
+		inst->pool->secure = secure;
dc8c34
 
dc8c34
 		if ((ludp->lud_port==0) && inst->pool->secure)
dc8c34
 			inst->pool->port=CB_LDAP_SECURE_PORT;
dc8c34
 		else
dc8c34
-               		inst->pool->port = ludp->lud_port;
dc8c34
+			inst->pool->port = ludp->lud_port;
dc8c34
 
dc8c34
 		/* Build a charray of <host>:<port> */
dc8c34
 		/* hostname is of the form <host>[:port] <host>[:port] */
dc8c34
diff --git a/ldap/servers/plugins/replication/repl5_replica.c b/ldap/servers/plugins/replication/repl5_replica.c
dc8c34
index 8187be9..82c30c1 100644
dc8c34
--- a/ldap/servers/plugins/replication/repl5_replica.c
dc8c34
+++ b/ldap/servers/plugins/replication/repl5_replica.c
dc8c34
@@ -2232,6 +2232,7 @@ _replica_configure_ruv  (Replica *r, PRBool isLocked)
dc8c34
 								"failed to recreate replica ruv tombstone entry"
dc8c34
 								" (%s); LDAP error - %d\n",
dc8c34
 								slapi_sdn_get_dn(r->repl_root), rc);
dc8c34
+							slapi_ch_free_string(&generation);
dc8c34
 							goto done;
dc8c34
 						}
dc8c34
 					}
dc8c34
@@ -2239,7 +2240,7 @@ _replica_configure_ruv  (Replica *r, PRBool isLocked)
dc8c34
 #undef RUV_UPDATE_FULL
dc8c34
 				}
dc8c34
 
dc8c34
-			    slapi_ch_free((void **)&generation);
dc8c34
+			    slapi_ch_free_string(&generation);
dc8c34
 			    return_value = 0;
dc8c34
 		    }
dc8c34
             else
dc8c34
diff --git a/ldap/servers/plugins/replication/repl5_replica_config.c b/ldap/servers/plugins/replication/repl5_replica_config.c
dc8c34
index d020ffb..1390ab4 100644
dc8c34
--- a/ldap/servers/plugins/replication/repl5_replica_config.c
dc8c34
+++ b/ldap/servers/plugins/replication/repl5_replica_config.c
dc8c34
@@ -1022,8 +1022,6 @@ static int replica_execute_cl2ldif_task (Object *r, char *returntext)
dc8c34
     }
dc8c34
 
dc8c34
     PR_snprintf (fName, MAXPATHLEN, "%s/%s.ldif", clDir, replica_get_name (replica));
dc8c34
-    slapi_ch_free_string (&clDir);
dc8c34
-
dc8c34
     slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name,
dc8c34
                     "Beginning changelog export of replica \"%s\"\n",
dc8c34
                     replica_get_name(replica));
dc8c34
@@ -1042,6 +1040,8 @@ static int replica_execute_cl2ldif_task (Object *r, char *returntext)
dc8c34
         rc = LDAP_OPERATIONS_ERROR;
dc8c34
     }
dc8c34
 bail:
dc8c34
+    slapi_ch_free_string (&clDir);
dc8c34
+
dc8c34
     return rc;
dc8c34
 }
dc8c34
 
dc8c34
@@ -1097,7 +1097,6 @@ static int replica_execute_ldif2cl_task (Object *r, char *returntext)
dc8c34
                     "Beginning changelog import of replica \"%s\"\n",
dc8c34
                     replica_get_name(replica));
dc8c34
     imprc = cl5ImportLDIF (clDir, fName, rlist);
dc8c34
-    slapi_ch_free_string (&clDir);
dc8c34
     if (CL5_SUCCESS == imprc)
dc8c34
     {
dc8c34
         slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name,
dc8c34
@@ -1127,8 +1126,11 @@ static int replica_execute_ldif2cl_task (Object *r, char *returntext)
dc8c34
             config.dir?config.dir:"null config dir");
dc8c34
         rc = LDAP_OPERATIONS_ERROR;
dc8c34
     }
dc8c34
+
dc8c34
 bail:
dc8c34
+    slapi_ch_free_string(&clDir);
dc8c34
     changelog5_config_done(&config);
dc8c34
+
dc8c34
     /* if cl5ImportLDIF returned an error, report it first. */
dc8c34
     return imprc?imprc:rc;
dc8c34
 }
dc8c34
@@ -2095,9 +2097,12 @@ replica_send_cleanruv_task(Repl_Agmt *agmt, cleanruv_data *clean_data)
dc8c34
     rc = ldap_modify_ext_s( ld, repl_dn, mods, NULL, NULL);
dc8c34
 
dc8c34
     if(rc != LDAP_SUCCESS){
dc8c34
+        char *hostname = agmt_get_hostname(agmt);
dc8c34
+
dc8c34
         cleanruv_log(clean_data->task, CLEANALLRUV_ID, "Failed to add CLEANRUV task (%s) to replica "
dc8c34
             "(%s).  You will need to manually run the CLEANRUV task on this replica (%s) error (%d)",
dc8c34
-            repl_dn, agmt_get_long_name(agmt), agmt_get_hostname(agmt), rc);
dc8c34
+            repl_dn, agmt_get_long_name(agmt), hostname, rc);
dc8c34
+        slapi_ch_free_string(&hostname);
dc8c34
     }
dc8c34
     slapi_ch_free_string(&repl_dn);
dc8c34
     slapi_sdn_free(&sdn;;
dc8c34
diff --git a/ldap/servers/slapd/back-ldbm/upgrade.c b/ldap/servers/slapd/back-ldbm/upgrade.c
dc8c34
index a10ee9b..16d784e 100644
dc8c34
--- a/ldap/servers/slapd/back-ldbm/upgrade.c
dc8c34
+++ b/ldap/servers/slapd/back-ldbm/upgrade.c
dc8c34
@@ -168,6 +168,7 @@ check_db_version( struct ldbminfo *li, int *action )
dc8c34
     *action = 0;
dc8c34
     dbversion_read(li, li->li_directory, &ldbmversion, &dataversion);
dc8c34
     if (NULL == ldbmversion || '\0' == *ldbmversion) {
dc8c34
+        slapi_ch_free_string(&ldbmversion);
dc8c34
         slapi_ch_free_string(&dataversion);
dc8c34
         return 0;
dc8c34
     }
dc8c34
@@ -251,6 +252,8 @@ check_db_inst_version( ldbm_instance *inst )
dc8c34
 
dc8c34
     dbversion_read(inst->inst_li, inst_dirp, &ldbmversion, &dataversion);
dc8c34
     if (NULL == ldbmversion || '\0' == *ldbmversion) {
dc8c34
+        slapi_ch_free_string(&ldbmversion);
dc8c34
+        slapi_ch_free_string(&dataversion);
dc8c34
         return rval;
dc8c34
     }
dc8c34
     
dc8c34
diff --git a/ldap/servers/slapd/main.c b/ldap/servers/slapd/main.c
dc8c34
index 53cb5c8..737da5d 100644
dc8c34
--- a/ldap/servers/slapd/main.c
dc8c34
+++ b/ldap/servers/slapd/main.c
dc8c34
@@ -2916,7 +2916,7 @@ slapd_debug_level_string2level( const char *s )
dc8c34
         char    *cur, *next, *scopy;
dc8c34
 
dc8c34
         level = 0;
dc8c34
-        cur = scopy = slapi_ch_strdup( s );     
dc8c34
+        scopy = slapi_ch_strdup( s );
dc8c34
 
dc8c34
         for ( cur = scopy; cur != NULL; cur = next ) {
dc8c34
                 if (( next = strchr( cur, '+' )) != NULL ) {
dc8c34
@@ -2936,12 +2936,13 @@ slapd_debug_level_string2level( const char *s )
dc8c34
 
dc8c34
                         if ( NULL == slapd_debug_level_map[i].dle_string ) {
dc8c34
                                 fprintf( stderr, "Unrecognized debug level \"%s\"\n", cur );
dc8c34
+                                slapi_ch_free_string(&scopy);
dc8c34
                                 return -1;
dc8c34
                         }
dc8c34
                 }
dc8c34
         }
dc8c34
 
dc8c34
-        slapi_ch_free( (void **)&scopy );
dc8c34
+        slapi_ch_free_string(&scopy);
dc8c34
 
dc8c34
         return level;
dc8c34
 }
dc8c34
diff --git a/ldap/servers/slapd/proxyauth.c b/ldap/servers/slapd/proxyauth.c
dc8c34
index 562ac93..17b6a05 100644
dc8c34
--- a/ldap/servers/slapd/proxyauth.c
dc8c34
+++ b/ldap/servers/slapd/proxyauth.c
dc8c34
@@ -181,11 +181,11 @@ parse_LDAPProxyAuth(struct berval *spec_ber, int version, char **errtextp,
dc8c34
 int
dc8c34
 proxyauth_get_dn( Slapi_PBlock *pb, char **proxydnp, char **errtextp )
dc8c34
 {
dc8c34
-  char *dn = 0;
dc8c34
-  LDAPProxyAuth *spec = 0;
dc8c34
-  int rv, lderr = LDAP_SUCCESS;	/* optimistic */
dc8c34
+	char *dn = 0;
dc8c34
+	LDAPProxyAuth *spec = 0;
dc8c34
+	int rv, lderr = LDAP_SUCCESS;	/* optimistic */
dc8c34
 
dc8c34
-  	BEGIN
dc8c34
+	BEGIN
dc8c34
 		struct berval *spec_ber;
dc8c34
 		LDAPControl **controls;
dc8c34
 		int present;
dc8c34
@@ -233,12 +233,12 @@ proxyauth_get_dn( Slapi_PBlock *pb, char **proxydnp, char **errtextp )
dc8c34
 		}
dc8c34
 	END
dc8c34
 
dc8c34
-    if (spec) delete_LDAPProxyAuth(spec);
dc8c34
+	if (spec) delete_LDAPProxyAuth(spec);
dc8c34
 
dc8c34
 	if ( NULL != proxydnp ) {
dc8c34
 		*proxydnp = dn;
dc8c34
 	} else {
dc8c34
-		slapi_ch_free( (void **)&dn );
dc8c34
+		slapi_ch_free_string(&dn;;
dc8c34
 	}
dc8c34
 
dc8c34
 	return lderr;
dc8c34
-- 
dc8c34
1.8.1.4
dc8c34