From 5a14af5f84914e733461ff316f5ab7684252136c Mon Sep 17 00:00:00 2001
From: Hallvard Furuseth <hallvard@openldap.org>
Date: Wed, 11 Nov 1998 22:10:05 +0000
Subject: [PATCH] Memory leaks: Values from ldap_get_dn were not freed.

---
 clients/ud/find.c | 10 ++++++++--
 clients/ud/mod.c  |  2 ++
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/clients/ud/find.c b/clients/ud/find.c
index 90c449c056..caa8f8ef69 100644
--- a/clients/ud/find.c
+++ b/clients/ud/find.c
@@ -235,7 +235,10 @@ int quiet;
 			ldap_set_option(ld, LDAP_OPT_DEREF, &savederef);
 			return(NULL);
 		} else if (matches == 1) {
-			if (ldap_search_s(ld, ldap_get_dn(ld, ldap_first_entry(ld, res)), LDAP_SCOPE_BASE, "objectClass=*", read_attrs, FALSE, &res) != LDAP_SUCCESS) {
+			dn = ldap_get_dn(ld, ldap_first_entry(ld, res));
+			rc = ldap_search_s(ld, dn, LDAP_SCOPE_BASE, "objectClass=*", read_attrs, FALSE, &res);
+			Free(dn);
+			if (rc != LDAP_SUCCESS) {
 				int ld_errno = 0;
 				ldap_get_option(ld, LDAP_OPT_ERROR_NUMBER, &ld_errno);
 				if (ld_errno == LDAP_UNAVAILABLE)
@@ -301,7 +304,10 @@ int quiet;
 				fflush(stdout);
 				fetch_buffer(response, sizeof(response), stdin);
 				if ((response[0] == 'n') || (response[0] == 'N'))
+				{
+					Free(dn);
 					return(NULL);
+				}
 			}
 #ifdef DEBUG
 			if (debug & D_FIND) {
@@ -320,7 +326,7 @@ int quiet;
 			if (ldap_search_s(ld, dn, LDAP_SCOPE_BASE, "objectClass=*", read_attrs, FALSE, &res) != LDAP_SUCCESS) {
 				ldap_perror(ld, "ldap_search_s");
 				ldap_msgfree(res);
-				return(NULL);
+				res = NULL;
 			}
 			Free(dn);
 			return(res);
diff --git a/clients/ud/mod.c b/clients/ud/mod.c
index b4a7c1f75e..6b26ccd3c7 100644
--- a/clients/ud/mod.c
+++ b/clients/ud/mod.c
@@ -21,6 +21,7 @@
 #include <lber.h>
 #include <ldap.h>
 #include "ud.h"
+extern void Free();
 
 extern struct entry Entry; 
 extern int verbose;
@@ -497,6 +498,7 @@ mail_is_good:
 			}
 			tmp = ldap_get_dn(ld, elmp);
 			strcpy(buffer, tmp);
+			Free(tmp);
 			(void) ldap_msgfree(lmp);
 			break;
 		}
-- 
GitLab