Blob Blame Raw
From ed7316fc2e770c4e0c877e220434489318735c76 Mon Sep 17 00:00:00 2001
From: Noriko Hosoi <nhosoi@redhat.com>
Date: Tue, 9 Sep 2014 14:27:40 -0700
Subject: [PATCH 2/7] 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 mreynolds@redhat.com (Thank you, Mark!!)

(cherry picked from commit 1279f0e0fe1d0f5456e42ef5b7a9f395f793cc9e)
(cherry picked from commit aa8ff4b066243f68175f2e664239b7db8747e1d1)
---
 ldap/servers/slapd/tools/migratecred.c       | 13 ++++++++++++-
 ldap/servers/slapd/tools/rsearch/nametable.c | 13 ++++++++-----
 2 files changed, 20 insertions(+), 6 deletions(-)

diff --git a/ldap/servers/slapd/tools/migratecred.c b/ldap/servers/slapd/tools/migratecred.c
index 085a21a..c1e37bf 100644
--- a/ldap/servers/slapd/tools/migratecred.c
+++ b/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);
 	
 }
diff --git a/ldap/servers/slapd/tools/rsearch/nametable.c b/ldap/servers/slapd/tools/rsearch/nametable.c
index e5d04cd..03a6ae1 100644
--- a/ldap/servers/slapd/tools/rsearch/nametable.c
+++ b/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;
-- 
1.9.3