@@ -1403,10 +1403,11 @@ static void php_set_opts(LDAP *ldap, int sizelimit, int timelimit, int deref, in
14031403static  void  php_ldap_do_search (INTERNAL_FUNCTION_PARAMETERS , int  scope )
14041404{
14051405	zval  * link , * attrs  =  NULL , * serverctrls  =  NULL ;
1406- 	zend_string  * base_dn_str , * filter_str ;
1407- 	HashTable  * base_dn_ht , * filter_ht ;
1406+ 	HashTable  * base_dn_ht  =  NULL ;
1407+ 	zend_string  * base_dn_str  =  NULL ;
1408+ 	HashTable  * filter_ht  =  NULL ;
1409+ 	zend_string  * filter_str  =  NULL ;
14081410	zend_long  attrsonly , sizelimit , timelimit , deref ;
1409- 	zend_string  * ldap_filter  =  NULL , * ldap_base_dn  =  NULL ;
14101411	char  * * ldap_attrs  =  NULL ;
14111412	ldap_linkdata  * ld  =  NULL ;
14121413	ldap_resultdata  * result ;
@@ -1486,6 +1487,8 @@ static void php_ldap_do_search(INTERNAL_FUNCTION_PARAMETERS, int scope)
14861487
14871488	/* parallel search? */ 
14881489	if  (Z_TYPE_P (link ) ==  IS_ARRAY ) {
1490+ 		const  zend_string  * ldap_base_dn  =  NULL ;
1491+ 		const  zend_string  * ldap_filter  =  NULL ;
14891492		uint32_t  num_links  =  zend_hash_num_elements (Z_ARRVAL_P (link ));
14901493		if  (num_links  ==  0 ) {
14911494			zend_argument_must_not_be_empty_error (1 );
@@ -1517,7 +1520,7 @@ static void php_ldap_do_search(INTERNAL_FUNCTION_PARAMETERS, int scope)
15171520				ret  =  0 ;
15181521				goto cleanup ;
15191522			}
1520- 			ldap_base_dn  =  zend_string_copy ( base_dn_str ) ;
1523+ 			ldap_base_dn  =  base_dn_str ;
15211524		}
15221525
15231526		uint32_t  num_filters  =  0 ; /* If 0 this means we are working with a unique base dn */ 
@@ -1539,7 +1542,7 @@ static void php_ldap_do_search(INTERNAL_FUNCTION_PARAMETERS, int scope)
15391542				ret  =  0 ;
15401543				goto cleanup ;
15411544			}
1542- 			ldap_filter  =  zend_string_copy ( filter_str ) ;
1545+ 			ldap_filter  =  filter_str ;
15431546		}
15441547
15451548		int  * rcs ;
@@ -1573,7 +1576,7 @@ static void php_ldap_do_search(INTERNAL_FUNCTION_PARAMETERS, int scope)
15731576					ret  =  0 ;
15741577					goto cleanup_parallel ;
15751578				}
1576- 				ldap_base_dn  =  zend_string_copy ( Z_STR_P (base_dn_zv ) );
1579+ 				ldap_base_dn  =  Z_STR_P (base_dn_zv );
15771580				if  (zend_str_has_nul_byte (ldap_base_dn )) {
15781581					zend_argument_value_error (2 , "must not contain null bytes" );
15791582					ret  =  0 ;
@@ -1589,7 +1592,7 @@ static void php_ldap_do_search(INTERNAL_FUNCTION_PARAMETERS, int scope)
15891592					ret  =  0 ;
15901593					goto cleanup_parallel ;
15911594				}
1592- 				ldap_filter  =  zend_string_copy ( Z_STR_P (filter_zv ) );
1595+ 				ldap_filter  =  Z_STR_P (filter_zv );
15931596				if  (zend_str_has_nul_byte (ldap_filter )) {
15941597					zend_argument_value_error (3 , "must not contain null bytes" );
15951598					ret  =  0 ;
@@ -1651,14 +1654,12 @@ static void php_ldap_do_search(INTERNAL_FUNCTION_PARAMETERS, int scope)
16511654			ret  =  0 ;
16521655			goto cleanup ;
16531656		}
1654- 		ldap_base_dn  =  zend_string_copy (base_dn_str );
16551657
16561658		if  (!filter_str ) {
16571659			zend_argument_type_error (3 , "must be of type string when argument #1 ($ldap) is an LDAP instance" );
16581660			ret  =  0 ;
16591661			goto cleanup ;
16601662		}
1661- 		ldap_filter  =  zend_string_copy (filter_str );
16621663
16631664		if  (serverctrls ) {
16641665			lserverctrls  =  _php_ldap_controls_from_array (ld -> link , serverctrls , 9 );
@@ -1671,7 +1672,7 @@ static void php_ldap_do_search(INTERNAL_FUNCTION_PARAMETERS, int scope)
16711672		php_set_opts (ld -> link , ldap_sizelimit , ldap_timelimit , ldap_deref , & old_ldap_sizelimit , & old_ldap_timelimit , & old_ldap_deref );
16721673
16731674		/* Run the actual search */ 
1674- 		ldap_errno  =  ldap_search_ext_s (ld -> link , ZSTR_VAL (ldap_base_dn ), scope , ZSTR_VAL (ldap_filter ), ldap_attrs , ldap_attrsonly , lserverctrls , NULL , NULL , ldap_sizelimit , & ldap_res );
1675+ 		ldap_errno  =  ldap_search_ext_s (ld -> link , ZSTR_VAL (base_dn_str ), scope , ZSTR_VAL (filter_str ), ldap_attrs , ldap_attrsonly , lserverctrls , NULL , NULL , ldap_sizelimit , & ldap_res );
16751676
16761677		if  (ldap_errno  !=  LDAP_SUCCESS 
16771678			&&  ldap_errno  !=  LDAP_SIZELIMIT_EXCEEDED 
@@ -1711,12 +1712,6 @@ static void php_ldap_do_search(INTERNAL_FUNCTION_PARAMETERS, int scope)
17111712		/* Restoring previous options */ 
17121713		php_set_opts (ld -> link , old_ldap_sizelimit , old_ldap_timelimit , old_ldap_deref , & ldap_sizelimit , & ldap_timelimit , & ldap_deref );
17131714	}
1714- 	if  (ldap_filter ) {
1715- 		zend_string_release (ldap_filter );
1716- 	}
1717- 	if  (ldap_base_dn ) {
1718- 		zend_string_release (ldap_base_dn );
1719- 	}
17201715	if  (ldap_attrs  !=  NULL ) {
17211716		efree (ldap_attrs );
17221717	}
0 commit comments