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