Browse Source

Ticket 47640 - Fix coverity issues - part 3

12504 - resource leak - /ldap/servers/slapd/back-ldbm/import-threads.c
12499 - resource leak - /ldap/servers/slapd/passwd_extop.c
12497 - resource leak - /ldap/servers/slapd/mapping_tree.c
12496 - resource leak - /ldap/servers/slapd/mapping_tree.c
12495 - resource leak - /ldap/servers/plugins/replication/legacy_consumer.c
12493 - resource leak - /ldap/servers/slapd/tools/rsearch/sdattable.c
12492 - resource leak - /ldap/servers/slapd/tools/pwenc.c
12491 - resource leak - /ldap/servers/slapd/tools/mmldif.c

https://fedorahosted.org/389/ticket/47740

Reviewed by: rmeggins(Thanks!)
Mark Reynolds 11 years ago
parent
commit
06919f531a

+ 5 - 5
ldap/servers/plugins/replication/legacy_consumer.c

@@ -371,11 +371,12 @@ legacy_consumer_config_modify (Slapi_PBlock *pb, Slapi_Entry* entryBefore, Slapi
                 {
                 {
                     if (mod_type == LDAP_MOD_REPLACE)
                     if (mod_type == LDAP_MOD_REPLACE)
                     {
                     {
+                        slapi_ch_free_string(&legacy_consumer_replicationpw);
                         legacy_consumer_replicationpw = config_copy_strval(config_attr_value);
                         legacy_consumer_replicationpw = config_copy_strval(config_attr_value);
                     }
                     }
                     else if (mod_type == LDAP_MOD_DELETE)
                     else if (mod_type == LDAP_MOD_DELETE)
                     {
                     {
-                        legacy_consumer_replicationpw = NULL;
+                        slapi_ch_free_string(&legacy_consumer_replicationpw);
                     }
                     }
                     else if (mod_type == LDAP_MOD_ADD)
                     else if (mod_type == LDAP_MOD_ADD)
                     {
                     {
@@ -387,6 +388,7 @@ legacy_consumer_config_modify (Slapi_PBlock *pb, Slapi_Entry* entryBefore, Slapi
                         }
                         }
                         else
                         else
                         {
                         {
+                            slapi_ch_free_string(&legacy_consumer_replicationpw);
                             legacy_consumer_replicationpw = config_copy_strval(config_attr_value);
                             legacy_consumer_replicationpw = config_copy_strval(config_attr_value);
                         }
                         }
                     }
                     }
@@ -419,11 +421,8 @@ legacy_consumer_config_delete (Slapi_PBlock *pb, Slapi_Entry* e, Slapi_Entry* en
 	slapi_rwlock_wrlock (legacy_consumer_config_lock);
 	slapi_rwlock_wrlock (legacy_consumer_config_lock);
     if (legacy_consumer_replicationdn)
     if (legacy_consumer_replicationdn)
         slapi_sdn_free (&legacy_consumer_replicationdn);
         slapi_sdn_free (&legacy_consumer_replicationdn);
-    if (legacy_consumer_replicationpw)
-        slapi_ch_free ((void**)&legacy_consumer_replicationpw);
-
+    slapi_ch_free_string(&legacy_consumer_replicationpw);
 	legacy_consumer_replicationdn = NULL;
 	legacy_consumer_replicationdn = NULL;
-    legacy_consumer_replicationpw = NULL;
 	slapi_rwlock_unlock (legacy_consumer_config_lock);
 	slapi_rwlock_unlock (legacy_consumer_config_lock);
 
 
 	*returncode = LDAP_SUCCESS;
 	*returncode = LDAP_SUCCESS;
@@ -446,6 +445,7 @@ legacy_consumer_extract_config(Slapi_Entry* entry, char *returntext)
 	    legacy_consumer_replicationdn = slapi_sdn_new_dn_passin (arg);
 	    legacy_consumer_replicationdn = slapi_sdn_new_dn_passin (arg);
 
 
     arg= slapi_entry_attr_get_charptr(entry,CONFIG_LEGACY_REPLICATIONPW_ATTRIBUTE);
     arg= slapi_entry_attr_get_charptr(entry,CONFIG_LEGACY_REPLICATIONPW_ATTRIBUTE);
+    slapi_ch_free_string(&legacy_consumer_replicationpw);
     legacy_consumer_replicationpw = arg;
     legacy_consumer_replicationpw = arg;
 
 
 	slapi_rwlock_unlock (legacy_consumer_config_lock);
 	slapi_rwlock_unlock (legacy_consumer_config_lock);

+ 1 - 0
ldap/servers/slapd/back-ldbm/import-threads.c

@@ -2621,6 +2621,7 @@ import_foreman(void *param)
                                             "of the duplicated entry %s; "
                                             "of the duplicated entry %s; "
                                             "Entry ID: %d", 
                                             "Entry ID: %d", 
                                             orig_dn, fi->entry->ep_id);
                                             orig_dn, fi->entry->ep_id);
+                    slapi_ch_free_string(&orig_dn);
                     goto cont;
                     goto cont;
                 }
                 }
                 new_entrydn = slapi_attr_new();
                 new_entrydn = slapi_attr_new();

+ 24 - 8
ldap/servers/slapd/mapping_tree.c

@@ -1132,6 +1132,8 @@ int mapping_tree_entry_modify_callback(Slapi_PBlock *pb, Slapi_Entry* entryBefor
                           "Error: could not find parent for %s\n",
                           "Error: could not find parent for %s\n",
                           slapi_entry_get_dn(entryAfter), 0, 0);
                           slapi_entry_get_dn(entryAfter), 0, 0);
                     slapi_sdn_free(&subtree);
                     slapi_sdn_free(&subtree);
+                    slapi_ch_free_string(&plugin_fct);
+                    slapi_ch_free_string(&plugin_lib);
                     *returncode = LDAP_UNWILLING_TO_PERFORM;
                     *returncode = LDAP_UNWILLING_TO_PERFORM;
                     return SLAPI_DSE_CALLBACK_ERROR;
                     return SLAPI_DSE_CALLBACK_ERROR;
                 }
                 }
@@ -1170,6 +1172,8 @@ int mapping_tree_entry_modify_callback(Slapi_PBlock *pb, Slapi_Entry* entryBefor
             {
             {
                 free_mapping_tree_node_arrays(&backends, &be_names, &be_states, &be_list_count);
                 free_mapping_tree_node_arrays(&backends, &be_names, &be_states, &be_list_count);
                 slapi_sdn_free(&subtree);
                 slapi_sdn_free(&subtree);
+                slapi_ch_free_string(&plugin_fct);
+                slapi_ch_free_string(&plugin_lib);
                 *returncode = LDAP_UNWILLING_TO_PERFORM;
                 *returncode = LDAP_UNWILLING_TO_PERFORM;
                 return SLAPI_DSE_CALLBACK_ERROR;
                 return SLAPI_DSE_CALLBACK_ERROR;
             }
             }
@@ -1183,6 +1187,8 @@ int mapping_tree_entry_modify_callback(Slapi_PBlock *pb, Slapi_Entry* entryBefor
                 mtn_unlock();
                 mtn_unlock();
                 free_mapping_tree_node_arrays(&backends, &be_names, &be_states, &be_list_count);
                 free_mapping_tree_node_arrays(&backends, &be_names, &be_states, &be_list_count);
                 slapi_sdn_free(&subtree);
                 slapi_sdn_free(&subtree);
+                slapi_ch_free_string(&plugin_fct);
+                slapi_ch_free_string(&plugin_lib);
                 return SLAPI_DSE_CALLBACK_ERROR;
                 return SLAPI_DSE_CALLBACK_ERROR;
             }
             }
 
 
@@ -1211,12 +1217,16 @@ int mapping_tree_entry_modify_callback(Slapi_PBlock *pb, Slapi_Entry* entryBefor
                 PR_snprintf(returntext, SLAPI_DSE_RETURNTEXT_SIZE, "must use replace operation to change state\n");
                 PR_snprintf(returntext, SLAPI_DSE_RETURNTEXT_SIZE, "must use replace operation to change state\n");
                 *returncode = LDAP_UNWILLING_TO_PERFORM;
                 *returncode = LDAP_UNWILLING_TO_PERFORM;
                 slapi_sdn_free(&subtree);
                 slapi_sdn_free(&subtree);
+                slapi_ch_free_string(&plugin_fct);
+                slapi_ch_free_string(&plugin_lib);
                 return SLAPI_DSE_CALLBACK_ERROR;
                 return SLAPI_DSE_CALLBACK_ERROR;
             }
             }
             if ((mods[i]->mod_bvalues == NULL) || (mods[i]->mod_bvalues[0] == NULL))
             if ((mods[i]->mod_bvalues == NULL) || (mods[i]->mod_bvalues[0] == NULL))
             {
             {
                 slapi_sdn_free(&subtree);
                 slapi_sdn_free(&subtree);
                 *returncode = LDAP_OPERATIONS_ERROR;
                 *returncode = LDAP_OPERATIONS_ERROR;
+                slapi_ch_free_string(&plugin_fct);
+                slapi_ch_free_string(&plugin_lib);
                 return SLAPI_DSE_CALLBACK_ERROR;
                 return SLAPI_DSE_CALLBACK_ERROR;
             }
             }
 
 
@@ -1230,6 +1240,8 @@ int mapping_tree_entry_modify_callback(Slapi_PBlock *pb, Slapi_Entry* entryBefor
                 {
                 {
                     PR_snprintf(returntext, SLAPI_DSE_RETURNTEXT_SIZE, "need to set nsslapd-backend before moving to backend state\n");
                     PR_snprintf(returntext, SLAPI_DSE_RETURNTEXT_SIZE, "need to set nsslapd-backend before moving to backend state\n");
                     slapi_sdn_free(&subtree);
                     slapi_sdn_free(&subtree);
+                    slapi_ch_free_string(&plugin_fct);
+                    slapi_ch_free_string(&plugin_lib);
                     *returncode = LDAP_UNWILLING_TO_PERFORM;
                     *returncode = LDAP_UNWILLING_TO_PERFORM;
                     return SLAPI_DSE_CALLBACK_ERROR;
                     return SLAPI_DSE_CALLBACK_ERROR;
                 }
                 }
@@ -1242,6 +1254,8 @@ int mapping_tree_entry_modify_callback(Slapi_PBlock *pb, Slapi_Entry* entryBefor
                 {
                 {
                     PR_snprintf(returntext, SLAPI_DSE_RETURNTEXT_SIZE, "need to set nsslapd-referral before moving to referral state\n");
                     PR_snprintf(returntext, SLAPI_DSE_RETURNTEXT_SIZE, "need to set nsslapd-referral before moving to referral state\n");
                     slapi_sdn_free(&subtree);
                     slapi_sdn_free(&subtree);
+                    slapi_ch_free_string(&plugin_fct);
+                    slapi_ch_free_string(&plugin_lib);
                     *returncode = LDAP_UNWILLING_TO_PERFORM;
                     *returncode = LDAP_UNWILLING_TO_PERFORM;
                     return SLAPI_DSE_CALLBACK_ERROR;
                     return SLAPI_DSE_CALLBACK_ERROR;
                 }
                 }
@@ -1280,6 +1294,8 @@ int mapping_tree_entry_modify_callback(Slapi_PBlock *pb, Slapi_Entry* entryBefor
                     *returncode = LDAP_UNWILLING_TO_PERFORM;
                     *returncode = LDAP_UNWILLING_TO_PERFORM;
                     mtn_unlock();
                     mtn_unlock();
                     slapi_sdn_free(&subtree);
                     slapi_sdn_free(&subtree);
+                    slapi_ch_free_string(&plugin_fct);
+                    slapi_ch_free_string(&plugin_lib);
                     return SLAPI_DSE_CALLBACK_ERROR;
                     return SLAPI_DSE_CALLBACK_ERROR;
                 }
                 }
 
 
@@ -1353,7 +1369,7 @@ int mapping_tree_entry_modify_callback(Slapi_PBlock *pb, Slapi_Entry* entryBefor
             if (SLAPI_IS_MOD_REPLACE(mods[i]->mod_op)
             if (SLAPI_IS_MOD_REPLACE(mods[i]->mod_op)
                 || SLAPI_IS_MOD_ADD(mods[i]->mod_op))
                 || SLAPI_IS_MOD_ADD(mods[i]->mod_op))
             {
             {
-		const char *sval;
+                const char *sval;
                 slapi_entry_attr_find(entryAfter,
                 slapi_entry_attr_find(entryAfter,
                              "nsslapd-distribution-root-update", &attr);
                              "nsslapd-distribution-root-update", &attr);
                 slapi_attr_first_value(attr, &val);
                 slapi_attr_first_value(attr, &val);
@@ -1365,13 +1381,13 @@ int mapping_tree_entry_modify_callback(Slapi_PBlock *pb, Slapi_Entry* entryBefor
                     plugin_rootmode = CHAIN_ROOT_UPDATE_REJECT;
                     plugin_rootmode = CHAIN_ROOT_UPDATE_REJECT;
                 } else {
                 } else {
                     sval = slapi_value_get_string(val);
                     sval = slapi_value_get_string(val);
-	    	    if (strcmp(sval,"reject") == 0)
-			plugin_rootmode = CHAIN_ROOT_UPDATE_REJECT;
-	    	    else if (strcmp(sval,"local") == 0)
-			plugin_rootmode = CHAIN_ROOT_UPDATE_LOCAL;
-	    	    else if (strcmp(sval,"referral") == 0)
-			plugin_rootmode = CHAIN_ROOT_UPDATE_REFERRAL;
-		}
+                    if (strcmp(sval,"reject") == 0)
+                        plugin_rootmode = CHAIN_ROOT_UPDATE_REJECT;
+                    else if (strcmp(sval,"local") == 0)
+                        plugin_rootmode = CHAIN_ROOT_UPDATE_LOCAL;
+                    else if (strcmp(sval,"referral") == 0)
+                        plugin_rootmode = CHAIN_ROOT_UPDATE_REFERRAL;
+                }
             }
             }
             else if (SLAPI_IS_MOD_DELETE(mods[i]->mod_op))
             else if (SLAPI_IS_MOD_DELETE(mods[i]->mod_op))
             {
             {

+ 1 - 3
ldap/servers/slapd/passwd_extop.c

@@ -904,7 +904,6 @@ static char *passwd_name_list[] = {
 int passwd_modify_init( Slapi_PBlock *pb )
 int passwd_modify_init( Slapi_PBlock *pb )
 {
 {
 	char	**argv;
 	char	**argv;
-	char	*oid;
 
 
 	/* Get the arguments appended to the plugin extendedop directive. The first argument 
 	/* Get the arguments appended to the plugin extendedop directive. The first argument 
 	 * (after the standard arguments for the directive) should contain the OID of the
 	 * (after the standard arguments for the directive) should contain the OID of the
@@ -923,9 +922,8 @@ int passwd_modify_init( Slapi_PBlock *pb )
 				 "OID is missing or is not %s\n", EXTOP_PASSWD_OID );
 				 "OID is missing or is not %s\n", EXTOP_PASSWD_OID );
 		return( -1 );
 		return( -1 );
 	} else {
 	} else {
-		oid = slapi_ch_strdup( argv[0] );
 		slapi_log_error( SLAPI_LOG_PLUGIN, "passwd_modify_init", 
 		slapi_log_error( SLAPI_LOG_PLUGIN, "passwd_modify_init", 
-				 "Registering plug-in for Password Modify extended op %s.\n", oid );
+				 "Registering plug-in for Password Modify extended op %s.\n", argv[0] /* oid */);
 	}
 	}
 
 
 	/* Register the plug-in function as an extended operation
 	/* Register the plug-in function as an extended operation

+ 2 - 0
ldap/servers/slapd/tools/mmldif.c

@@ -659,6 +659,7 @@ int mm_init(int argc, char * argv[])
             slapd_ldap_debug = 65535;
             slapd_ldap_debug = 65535;
             break;
             break;
         case 'o':
         case 'o':
+            if(ofn) free (ofn);
             ofn = strdup(optarg);
             ofn = strdup(optarg);
             break;
             break;
         case 'h':
         case 'h':
@@ -677,6 +678,7 @@ int mm_init(int argc, char * argv[])
         ofp = fopen(ofn, "w");
         ofp = fopen(ofn, "w");
         if (ofp == NULL) {
         if (ofp == NULL) {
             perror(ofn);
             perror(ofn);
+            free(ofn);
             return -1;
             return -1;
         }
         }
         free(ofn);
         free(ofn);

+ 3 - 1
ldap/servers/slapd/tools/pwenc.c

@@ -140,8 +140,10 @@ init_config(char *configdir)
 
 
     abs_configdir = rel2abspath( configdir );
     abs_configdir = rel2abspath( configdir );
     if ( config_set_configdir( "configdir (-D)", abs_configdir,
     if ( config_set_configdir( "configdir (-D)", abs_configdir,
-                               errorbuf, 1) != LDAP_SUCCESS ) {
+                               errorbuf, 1) != LDAP_SUCCESS )
+    {
         fprintf( stderr, "%s\n", errorbuf );
         fprintf( stderr, "%s\n", errorbuf );
+        slapi_ch_free_string(&abs_configdir);
         return( NULL );
         return( NULL );
     }
     }
     slapi_ch_free_string(&abs_configdir);
     slapi_ch_free_string(&abs_configdir);

+ 37 - 21
ldap/servers/slapd/tools/rsearch/sdattable.c

@@ -141,27 +141,43 @@ int sdt_load(SDatTable *sdt, const char *filename)
     if (!fd) return 0;
     if (!fd) return 0;
 
 
     while (PR_Available(fd) > 0) {
     while (PR_Available(fd) > 0) {
-	int rval;
-	char temp[256];
-	char *dn = NULL;
-	char *uid = NULL;
-	while (!(rval = PR_GetLine(fd, temp, 256))) {
-	    char *p;
-	    if (!strncasecmp(temp, "dn:", 3)) {
-		for (p = temp + 4; *p == ' ' || *p == '\t'; p++) ;
-	        dn = strdup(p);
-	        if (!dn) break;
-	    } else if (!strncasecmp(temp, "uid:", 4)) {
-		for (p = temp + 5; *p == ' ' || *p == '\t'; p++) ;
-	        uid = strdup(p);
-	        if (!uid) break;
-	    }
-	    if (uid) {	/* dn should come earlier than uid */
-	        if (!sdt_push(sdt, dn, uid)) goto out;
-		break;
-	    }
-	}
-	if (rval) break;	/* PR_GetLine failed */
+		int rval;
+		int pushed = 0;
+		char temp[256];
+		char *dn = NULL;
+		char *uid = NULL;
+		while (!(rval = PR_GetLine(fd, temp, 256))) {
+			char *p;
+			if (!strncasecmp(temp, "dn:", 3)) {
+				for (p = temp + 4; *p == ' ' || *p == '\t'; p++) ;
+				dn = strdup(p);
+				if (!dn) break;
+			} else if (!strncasecmp(temp, "uid:", 4)) {
+				for (p = temp + 5; *p == ' ' || *p == '\t'; p++) ;
+				uid = strdup(p);
+				if (!uid) break;
+			}
+			if (uid) {
+				/* dn should come earlier than uid - so both dn and uid must be set. */
+				if (!sdt_push(sdt, dn, uid)){
+					/* failure, free the dn and uid */
+					free(dn);
+					free(uid);
+					goto out;
+				}
+				pushed = 1;
+				break;
+			}
+		}
+		if(!pushed){
+			/*
+			 * Entry might not have been a user entry with a uid,
+			 * so free the dn just in case.
+			 */
+			if(dn)
+				free(dn);
+		}
+		if (rval) break;	/* PR_GetLine failed */
     }
     }
 out:
 out:
     PR_Close(fd);
     PR_Close(fd);