andykimpe / rpms / 389-ds-base

Forked from rpms/389-ds-base 5 months ago
Clone

Blame SOURCES/0002-Ticket-47890-minor-memory-leaks-in-utilities.patch

f92ce9
From ed7316fc2e770c4e0c877e220434489318735c76 Mon Sep 17 00:00:00 2001
f92ce9
From: Noriko Hosoi <nhosoi@redhat.com>
f92ce9
Date: Tue, 9 Sep 2014 14:27:40 -0700
f92ce9
Subject: [PATCH 2/7] Ticket #47890 - minor memory leaks in utilities
f92ce9
f92ce9
Description:
f92ce9
tools/rsearch/nametable.c - if nt_push fails and the strdup'ed
f92ce9
                            string is not pushed to the table,
f92ce9
                            free the string.
f92ce9
tools/migratecred.c - free strdup'ed strings oldpath, newpath,
f92ce9
                      prefixCred, and pluginpath at the end of
f92ce9
                      the process.
f92ce9
f92ce9
https://fedorahosted.org/389/ticket/47890
f92ce9
f92ce9
Reviewed by mreynolds@redhat.com (Thank you, Mark!!)
f92ce9
f92ce9
(cherry picked from commit 1279f0e0fe1d0f5456e42ef5b7a9f395f793cc9e)
f92ce9
(cherry picked from commit aa8ff4b066243f68175f2e664239b7db8747e1d1)
f92ce9
---
f92ce9
 ldap/servers/slapd/tools/migratecred.c       | 13 ++++++++++++-
f92ce9
 ldap/servers/slapd/tools/rsearch/nametable.c | 13 ++++++++-----
f92ce9
 2 files changed, 20 insertions(+), 6 deletions(-)
f92ce9
f92ce9
diff --git a/ldap/servers/slapd/tools/migratecred.c b/ldap/servers/slapd/tools/migratecred.c
f92ce9
index 085a21a..c1e37bf 100644
f92ce9
--- a/ldap/servers/slapd/tools/migratecred.c
f92ce9
+++ b/ldap/servers/slapd/tools/migratecred.c
f92ce9
@@ -163,6 +163,10 @@ main( int argc, char **argv)
f92ce9
 
f92ce9
 	if ( !oldpath || !newpath || !cred )
f92ce9
 	{
f92ce9
+		free(oldpath);
f92ce9
+		free(newpath);
f92ce9
+		free(prefixCred);
f92ce9
+		free(pluginpath);
f92ce9
 		usage(cmd);
f92ce9
 	}
f92ce9
 
f92ce9
@@ -208,6 +212,10 @@ main( int argc, char **argv)
f92ce9
 			"DES Plugin", 1 /* report errors */ );
f92ce9
 	if ( fct == NULL )
f92ce9
 	{
f92ce9
+		free(oldpath);
f92ce9
+		free(newpath);
f92ce9
+		free(prefixCred);
f92ce9
+		free(pluginpath);
f92ce9
 		usage(cmd);
f92ce9
 		return(1);
f92ce9
 	}
f92ce9
@@ -215,7 +223,10 @@ main( int argc, char **argv)
f92ce9
 	newcred = (fct)(oldpath, newpath, cred);
f92ce9
 
f92ce9
 	fprintf(stdout, "%s", newcred);
f92ce9
-
f92ce9
+	free(oldpath);
f92ce9
+	free(newpath);
f92ce9
+	free(prefixCred);
f92ce9
+	free(pluginpath);
f92ce9
 	return(0);
f92ce9
 	
f92ce9
 }
f92ce9
diff --git a/ldap/servers/slapd/tools/rsearch/nametable.c b/ldap/servers/slapd/tools/rsearch/nametable.c
f92ce9
index e5d04cd..03a6ae1 100644
f92ce9
--- a/ldap/servers/slapd/tools/rsearch/nametable.c
f92ce9
+++ b/ldap/servers/slapd/tools/rsearch/nametable.c
f92ce9
@@ -152,11 +152,14 @@ int nt_load(NameTable *nt, const char *filename)
f92ce9
     if (!fd) return 0;
f92ce9
 
f92ce9
     while (PR_Available(fd) > 0) {
f92ce9
-	char temp[4096], *s;
f92ce9
-	if (PR_GetLine(fd, temp, sizeof(temp))) break;
f92ce9
-	s = strdup(temp);
f92ce9
-	if (!s) break;
f92ce9
-	if (!nt_push(nt, s)) break;
f92ce9
+        char temp[4096], *s;
f92ce9
+        if (PR_GetLine(fd, temp, sizeof(temp))) break;
f92ce9
+        s = strdup(temp);
f92ce9
+        if (!s) break;
f92ce9
+        if (!nt_push(nt, s)) {
f92ce9
+            free(s);
f92ce9
+            break;
f92ce9
+        }
f92ce9
     }
f92ce9
     PR_Close(fd);
f92ce9
     return nt->size;
f92ce9
-- 
f92ce9
1.9.3
f92ce9