Browse Source

Ticket #47890 - minor memory leaks in utilities

Description:
tools/rsearch/nametable.c - if nt_push fails and the strdup'ed
                            string is not pushed to the table,
                            free the string.
tools/migratecred.c - free strdup'ed strings oldpath, newpath,
                      prefixCred, and pluginpath at the end of
                      the process.

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

Reviewed by [email protected] (Thank you, Mark!!)
Noriko Hosoi 11 years ago
parent
commit
1279f0e0fe

+ 12 - 1
ldap/servers/slapd/tools/migratecred.c

@@ -163,6 +163,10 @@ main( int argc, char **argv)
 
 	if ( !oldpath || !newpath || !cred )
 	{
+		free(oldpath);
+		free(newpath);
+		free(prefixCred);
+		free(pluginpath);
 		usage(cmd);
 	}
 
@@ -208,6 +212,10 @@ main( int argc, char **argv)
 			"DES Plugin", 1 /* report errors */ );
 	if ( fct == NULL )
 	{
+		free(oldpath);
+		free(newpath);
+		free(prefixCred);
+		free(pluginpath);
 		usage(cmd);
 		return(1);
 	}
@@ -215,7 +223,10 @@ main( int argc, char **argv)
 	newcred = (fct)(oldpath, newpath, cred);
 
 	fprintf(stdout, "%s", newcred);
-
+	free(oldpath);
+	free(newpath);
+	free(prefixCred);
+	free(pluginpath);
 	return(0);
 	
 }

+ 8 - 5
ldap/servers/slapd/tools/rsearch/nametable.c

@@ -152,11 +152,14 @@ int nt_load(NameTable *nt, const char *filename)
     if (!fd) return 0;
 
     while (PR_Available(fd) > 0) {
-	char temp[4096], *s;
-	if (PR_GetLine(fd, temp, sizeof(temp))) break;
-	s = strdup(temp);
-	if (!s) break;
-	if (!nt_push(nt, s)) break;
+        char temp[4096], *s;
+        if (PR_GetLine(fd, temp, sizeof(temp))) break;
+        s = strdup(temp);
+        if (!s) break;
+        if (!nt_push(nt, s)) {
+            free(s);
+            break;
+        }
     }
     PR_Close(fd);
     return nt->size;