From 661d5bec57ccaa989c81b9de63e5f810263e714e Mon Sep 17 00:00:00 2001
From: Quanah Gibson-Mount <quanah@openldap.org>
Date: Wed, 26 Jan 2011 19:20:45 +0000
Subject: [PATCH] ITS#6788

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

diff --git a/CHANGES b/CHANGES
index dbe4c1ff5f..b53d160313 100644
--- a/CHANGES
+++ b/CHANGES
@@ -33,6 +33,7 @@ OpenLDAP 2.4.24 Engineering
 	Fixed libldap referral chasing (ITS#6602)
 	Fixed libldap leak when chasing referrals (ITS#6744)
 	Fixed libldap url parsing with NULL host (ITS#6653)
+	Fixed libldap ldap_open_internal_connection (ITS#6788)
 	Fixed liblutil getpass prompts (ITS#6702)
 	Fixed ldapsearch segfault with deref (ITS#6638)
 	Fixed ldapsearch multiple controls parsing (ITS#6651)
diff --git a/libraries/libldap/open.c b/libraries/libldap/open.c
index 5cc653139f..306c3e40b1 100644
--- a/libraries/libldap/open.c
+++ b/libraries/libldap/open.c
@@ -447,6 +447,11 @@ ldap_int_open_connection(
 	return( 0 );
 }
 
+/*
+ * ldap_open_internal_connection - open connection and set file descriptor
+ *
+ * note: ldap_init_fd() may be preferable
+ */
 
 int
 ldap_open_internal_connection( LDAP **ldp, ber_socket_t *fdp )
@@ -504,6 +509,8 @@ ldap_open_internal_connection( LDAP **ldp, ber_socket_t *fdp )
 	ldap_set_option( ld, LDAP_OPT_PROTOCOL_VERSION, &rc );
 	*ldp = ld;
 
+	++ld->ld_defconn->lconn_refcnt;	/* so it never gets closed/freed */
+
 	return( LDAP_SUCCESS );
 }
 
-- 
GitLab