File 0022-Plug-a-socket-leak-in-ldap_new_connection-made-by-un.patch of Package openldap2.14904

From 70a603d5504b6a93d2d137fb56b13239a4d27df4 Mon Sep 17 00:00:00 2001
From: HouzuoGuo <guohouzuo@gmail.com>
Date: Thu, 30 Nov 2017 14:54:45 +0100
Subject: [PATCH] Plug a socket leak in ldap_new_connection made by
 unsuccessful connection attempts


diff --git a/libraries/libldap/request.c b/libraries/libldap/request.c
index c2d6dd4..1935400 100644
--- a/libraries/libldap/request.c
+++ b/libraries/libldap/request.c
@@ -485,7 +485,18 @@ ldap_new_connection( LDAP *ld, LDAPURLDesc **srvlist, int use_ldsb,
 			int		rc;
 
 			rc = ldap_int_open_connection( ld, lc, *srvp, async );
-			if ( rc != -1 ) {
+			if (rc == -1) {
+				ber_sockbuf_free( lc->lconn_sb );
+				lc->lconn_sb = ber_sockbuf_alloc();
+				if ( lc->lconn_sb == NULL ) {
+					LDAP_FREE( (char *)lc );
+					ld->ld_errno = LDAP_NO_MEMORY;
+					return( NULL );
+				}
+				if (use_ldsb) {
+					ld->ld_sb = lc->lconn_sb;
+				}
+			} else {
 				srv = *srvp;
 
 				/* If we fully connected, async is moot */
-- 
2.15.0
openSUSE Build Service is sponsored by