Skip to content

Commit 9dc58b3

Browse files
committed
ext/ldap: Remove unnecessary copy
I am faily certain this was just leaking memory
1 parent 9bc2a03 commit 9dc58b3

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);
@@ -1510,7 +1513,7 @@ static void php_ldap_do_search(INTERNAL_FUNCTION_PARAMETERS, int scope)
15101513
ret = 0;
15111514
goto cleanup;
15121515
}
1513-
ldap_base_dn = zend_string_copy(base_dn_str);
1516+
ldap_base_dn = base_dn_str;
15141517
}
15151518

15161519
uint32_t num_filters = 0; /* If 0 this means we are working with a unique base dn */
@@ -1531,7 +1534,7 @@ static void php_ldap_do_search(INTERNAL_FUNCTION_PARAMETERS, int scope)
15311534
ret = 0;
15321535
goto cleanup;
15331536
}
1534-
ldap_filter = zend_string_copy(filter_str);
1537+
ldap_filter = filter_str;
15351538
}
15361539

15371540
int *rcs;
@@ -1563,7 +1566,7 @@ static void php_ldap_do_search(INTERNAL_FUNCTION_PARAMETERS, int scope)
15631566
ret = 0;
15641567
goto cleanup_parallel;
15651568
}
1566-
ldap_base_dn = zend_string_copy(Z_STR_P(base_dn_zv));
1569+
ldap_base_dn = Z_STR_P(base_dn_zv);
15671570
if (zend_str_has_nul_byte(ldap_base_dn)) {
15681571
zend_argument_value_error(2, "must not contain null bytes");
15691572
ret = 0;
@@ -1578,7 +1581,7 @@ static void php_ldap_do_search(INTERNAL_FUNCTION_PARAMETERS, int scope)
15781581
ret = 0;
15791582
goto cleanup_parallel;
15801583
}
1581-
ldap_filter = zend_string_copy(Z_STR_P(filter_zv));
1584+
ldap_filter = Z_STR_P(filter_zv);
15821585
if (zend_str_has_nul_byte(ldap_filter)) {
15831586
zend_argument_value_error(3, "must not contain null bytes");
15841587
ret = 0;
@@ -1640,14 +1643,12 @@ static void php_ldap_do_search(INTERNAL_FUNCTION_PARAMETERS, int scope)
16401643
ret = 0;
16411644
goto cleanup;
16421645
}
1643-
ldap_base_dn = zend_string_copy(base_dn_str);
16441646

16451647
if (!filter_str) {
16461648
zend_argument_type_error(3, "must be of type string when argument #1 ($ldap) is an LDAP instance");
16471649
ret = 0;
16481650
goto cleanup;
16491651
}
1650-
ldap_filter = zend_string_copy(filter_str);
16511652

16521653
if (serverctrls) {
16531654
lserverctrls = _php_ldap_controls_from_array(ld->link, serverctrls, 9);
@@ -1660,7 +1661,7 @@ static void php_ldap_do_search(INTERNAL_FUNCTION_PARAMETERS, int scope)
16601661
php_set_opts(ld->link, ldap_sizelimit, ldap_timelimit, ldap_deref, &old_ldap_sizelimit, &old_ldap_timelimit, &old_ldap_deref);
16611662

16621663
/* Run the actual search */
1663-
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);
1664+
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);
16641665

16651666
if (ldap_errno != LDAP_SUCCESS
16661667
&& ldap_errno != LDAP_SIZELIMIT_EXCEEDED
@@ -1700,12 +1701,6 @@ static void php_ldap_do_search(INTERNAL_FUNCTION_PARAMETERS, int scope)
17001701
/* Restoring previous options */
17011702
php_set_opts(ld->link, old_ldap_sizelimit, old_ldap_timelimit, old_ldap_deref, &ldap_sizelimit, &ldap_timelimit, &ldap_deref);
17021703
}
1703-
if (ldap_filter) {
1704-
zend_string_release(ldap_filter);
1705-
}
1706-
if (ldap_base_dn) {
1707-
zend_string_release(ldap_base_dn);
1708-
}
17091704
if (ldap_attrs != NULL) {
17101705
efree(ldap_attrs);
17111706
}

0 commit comments

Comments
 (0)