From 518dd3a9a1ceb687e14eac9b04e322f1efe98833 Mon Sep 17 00:00:00 2001
From: Quanah Gibson-Mount <quanah@openldap.org>
Date: Tue, 4 Jan 2011 17:40:40 +0000
Subject: [PATCH] ITS#6744

---
 CHANGES                    | 1 +
 libraries/libldap/result.c | 7 +++++++
 2 files changed, 8 insertions(+)

diff --git a/CHANGES b/CHANGES
index 2e744f9406..63a0f5f667 100644
--- a/CHANGES
+++ b/CHANGES
@@ -16,6 +16,7 @@ OpenLDAP 2.4.24 Engineering
 	Fixed libldap GnuTLS hang on socket close (ITS#6673)
 	Fixed libldap sasl partial write handling (ITS#6639)
 	Fixed libldap referral chasing (ITS#6602)
+	Fixed libldap leak when chasing referrals (ITS#6744)
 	Fixed libldap url parsing with NULL host (ITS#6653)
 	Fixed liblutil getpass prompts (ITS#6702)
 	Fixed ldapsearch segfault with deref (ITS#6638)
diff --git a/libraries/libldap/result.c b/libraries/libldap/result.c
index 3fdf10d73b..0f08ca2f66 100644
--- a/libraries/libldap/result.c
+++ b/libraries/libldap/result.c
@@ -826,6 +826,7 @@ nextresp2:
 			Debug( LDAP_DEBUG_TRACE,
 				"read1msg:  mark request completed, ld %p msgid %d\n",
 				(void *)ld, lr->lr_msgid, 0);
+			tmplr = lr;
 			while ( lr->lr_parent != NULL ) {
 				merge_error_info( ld, lr->lr_parent, lr );
 
@@ -834,6 +835,12 @@ nextresp2:
 					break;	/* not completely done yet */
 				}
 			}
+			/* ITS#6744: Original lr was refcounted when we retrieved it,
+			 * must release it now that we're working with the parent
+			 */
+			if ( tmplr->lr_parent ) {
+				ldap_return_request( ld, tmplr, 0 );
+			}
 
 			/* Check if all requests are finished, lr is now parent */
 			tmplr = lr;
-- 
GitLab