From 8af02353152df0330d3d6a696ac6a1836f9d8416 Mon Sep 17 00:00:00 2001
From: Quanah Gibson-Mount <quanah@openldap.org>
Date: Sun, 12 Dec 2010 02:04:05 +0000
Subject: [PATCH] ITS#6638

---
 CHANGES                    | 1 +
 clients/tools/ldapsearch.c | 5 ++++-
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/CHANGES b/CHANGES
index 9665e94944..2beb452651 100644
--- a/CHANGES
+++ b/CHANGES
@@ -2,6 +2,7 @@ OpenLDAP 2.4 Change Log
 
 OpenLDAP 2.4.24 Engineering
 	Fixed liblber to not close invalid sockets (ITS#6585)
+	Fixed ldapsearch segfault with deref (ITS#6638)
 	Fixed slapd acl parsing overflow (ITS#6611)
 	Fixed slapd modify to return actual error (ITS#6581)
 	Fixed slapd-bdb entry cache delete failure (ITS#6577)
diff --git a/clients/tools/ldapsearch.c b/clients/tools/ldapsearch.c
index f06af7f570..eb64c37298 100644
--- a/clients/tools/ldapsearch.c
+++ b/clients/tools/ldapsearch.c
@@ -594,7 +594,7 @@ handle_private_option( int i )
 				exit( EXIT_FAILURE );
 			}
 			for ( ispecs = 0; specs[ ispecs ] != NULL; ispecs++ )
-				/* count'em */
+				/* count'em */ ;
 
 			ds = ldap_memcalloc( ispecs + 1, sizeof( LDAPDerefSpec ) );
 			if ( ds == NULL ) {
@@ -1334,6 +1334,9 @@ getNextPage:
 	if ( derefval.bv_val != NULL ) {
 		ldap_memfree( derefval.bv_val );
 	}
+	if ( def_urlpre != NULL ) {
+		ber_memfree( def_urlpre );
+	}
 
 	if ( c ) {
 		for ( ; save_nctrls-- > 0; ) {
-- 
GitLab