Skip to content

Commit ea92ed9

Browse files
committed
ext/ldap: Remove unnecessary copy
I am faily certain this was just leaking memory
1 parent 3f150f3 commit ea92ed9

File tree

1 file changed

+11
-16
lines changed

1 file changed

+11
-16
lines changed

ext/ldap/ldap.c

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1403,10 +1403,11 @@ static void php_set_opts(LDAP *ldap, int sizelimit, int timelimit, int deref, in
14031403
static 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;
@@ -1485,6 +1486,8 @@ static void php_ldap_do_search(INTERNAL_FUNCTION_PARAMETERS, int scope)
14851486

14861487
/* parallel search? */
14871488
if (Z_TYPE_P(link) == IS_ARRAY) {
1489+
const zend_string *ldap_base_dn = NULL;
1490+
const zend_string *ldap_filter = NULL;
14881491
uint32_t num_links = zend_hash_num_elements(Z_ARRVAL_P(link));
14891492
if (num_links == 0) {
14901493
zend_argument_must_not_be_empty_error(1);
@@ -1516,7 +1519,7 @@ static void php_ldap_do_search(INTERNAL_FUNCTION_PARAMETERS, int scope)
15161519
ret = 0;
15171520
goto cleanup;
15181521
}
1519-
ldap_base_dn = zend_string_copy(base_dn_str);
1522+
ldap_base_dn = base_dn_str;
15201523
}
15211524

15221525
uint32_t num_filters = 0; /* If 0 this means we are working with a unique base dn */
@@ -1538,7 +1541,7 @@ static void php_ldap_do_search(INTERNAL_FUNCTION_PARAMETERS, int scope)
15381541
ret = 0;
15391542
goto cleanup;
15401543
}
1541-
ldap_filter = zend_string_copy(filter_str);
1544+
ldap_filter = filter_str;
15421545
}
15431546

15441547
int *rcs;
@@ -1570,7 +1573,7 @@ static void php_ldap_do_search(INTERNAL_FUNCTION_PARAMETERS, int scope)
15701573
ret = 0;
15711574
goto cleanup_parallel;
15721575
}
1573-
ldap_base_dn = zend_string_copy(Z_STR_P(base_dn_zv));
1576+
ldap_base_dn = Z_STR_P(base_dn_zv);
15741577
if (zend_str_has_nul_byte(ldap_base_dn)) {
15751578
zend_argument_value_error(2, "must not contain null bytes");
15761579
ret = 0;
@@ -1585,7 +1588,7 @@ static void php_ldap_do_search(INTERNAL_FUNCTION_PARAMETERS, int scope)
15851588
ret = 0;
15861589
goto cleanup_parallel;
15871590
}
1588-
ldap_filter = zend_string_copy(Z_STR_P(filter_zv));
1591+
ldap_filter = Z_STR_P(filter_zv);
15891592
if (zend_str_has_nul_byte(ldap_filter)) {
15901593
zend_argument_value_error(3, "must not contain null bytes");
15911594
ret = 0;
@@ -1647,14 +1650,12 @@ static void php_ldap_do_search(INTERNAL_FUNCTION_PARAMETERS, int scope)
16471650
ret = 0;
16481651
goto cleanup;
16491652
}
1650-
ldap_base_dn = zend_string_copy(base_dn_str);
16511653

16521654
if (!filter_str) {
16531655
zend_argument_type_error(3, "must be of type string when argument #1 ($ldap) is an LDAP instance");
16541656
ret = 0;
16551657
goto cleanup;
16561658
}
1657-
ldap_filter = zend_string_copy(filter_str);
16581659

16591660
if (serverctrls) {
16601661
lserverctrls = _php_ldap_controls_from_array(ld->link, serverctrls, 9);
@@ -1667,7 +1668,7 @@ static void php_ldap_do_search(INTERNAL_FUNCTION_PARAMETERS, int scope)
16671668
php_set_opts(ld->link, ldap_sizelimit, ldap_timelimit, ldap_deref, &old_ldap_sizelimit, &old_ldap_timelimit, &old_ldap_deref);
16681669

16691670
/* Run the actual search */
1670-
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);
1671+
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);
16711672

16721673
if (ldap_errno != LDAP_SUCCESS
16731674
&& ldap_errno != LDAP_SIZELIMIT_EXCEEDED
@@ -1707,12 +1708,6 @@ static void php_ldap_do_search(INTERNAL_FUNCTION_PARAMETERS, int scope)
17071708
/* Restoring previous options */
17081709
php_set_opts(ld->link, old_ldap_sizelimit, old_ldap_timelimit, old_ldap_deref, &ldap_sizelimit, &ldap_timelimit, &ldap_deref);
17091710
}
1710-
if (ldap_filter) {
1711-
zend_string_release(ldap_filter);
1712-
}
1713-
if (ldap_base_dn) {
1714-
zend_string_release(ldap_base_dn);
1715-
}
17161711
if (ldap_attrs != NULL) {
17171712
efree(ldap_attrs);
17181713
}

0 commit comments

Comments
 (0)