diff --git a/CHANGES b/CHANGES
index dbe4c1ff5f30e84e13a1fe3387aae1ac05220ddf..b53d1603139037588c9cee52cd192f1bc0be2133 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 5cc653139f5442ac309670d9ab00ad048416f114..306c3e40b18963addfc32018adb5da6c1bf77f2f 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 );
 }