From 65f40d9e05115d9fae8ec15c722ccc3c862ef7e8 Mon Sep 17 00:00:00 2001
From: Quanah Gibson-Mount <quanah@openldap.org>
Date: Thu, 10 Jun 2010 19:39:48 +0000
Subject: [PATCH] ITS#6568

---
 CHANGES                     | 1 +
 libraries/libldap/request.c | 4 ++++
 libraries/libldap/unbind.c  | 5 +++++
 3 files changed, 10 insertions(+)

diff --git a/CHANGES b/CHANGES
index deaeb919da..b2b433e643 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,6 +1,7 @@
 OpenLDAP 2.4 Change Log
 
 OpenLDAP 2.4.23 Engineering
+	Fixed libldap memleaks (ITS#6568)
 	Fixed liblutil off-by-one with delta (ITS#6541)
 	Fixed slapd syncrepl rid logging (ITS#6533)
 	Fixed slapd-bdb hasSubordinates computation (ITS#6549)
diff --git a/libraries/libldap/request.c b/libraries/libldap/request.c
index 2c1e787bdf..205599300a 100644
--- a/libraries/libldap/request.c
+++ b/libraries/libldap/request.c
@@ -124,10 +124,14 @@ ldap_send_initial_request(
 			if (ld->ld_options.ldo_cldapdn)
 				ldap_memfree(ld->ld_options.ldo_cldapdn);
 			ld->ld_options.ldo_cldapdn = ldap_strdup(dn);
+			ber_free( ber, 1 );
 			return 0;
 		}
 		if (msgtype != LDAP_REQ_ABANDON && msgtype != LDAP_REQ_SEARCH)
+		{
+			ber_free( ber, 1 );
 			return LDAP_PARAM_ERROR;
+		}
 	}
 #endif
 #ifdef LDAP_R_COMPILE
diff --git a/libraries/libldap/unbind.c b/libraries/libldap/unbind.c
index 15e6ee4f1b..bd4df7a849 100644
--- a/libraries/libldap/unbind.c
+++ b/libraries/libldap/unbind.c
@@ -154,6 +154,11 @@ ldap_ld_free(
 		LDAP_FREE( ld->ld_options.ldo_peer );
 		ld->ld_options.ldo_peer = NULL;
 	}
+
+	if ( ld->ld_options.ldo_cldapdn != NULL ) {
+		LDAP_FREE( ld->ld_options.ldo_cldapdn );
+		ld->ld_options.ldo_cldapdn = NULL;
+	}
 #endif
 
 #ifdef HAVE_CYRUS_SASL
-- 
GitLab