diff options
| author | Côme Chilliet <mcmic@php.net> | 2017-09-14 10:08:22 +0200 |
|---|---|---|
| committer | Côme Chilliet <mcmic@php.net> | 2017-09-21 10:05:42 +0200 |
| commit | def30dbde2edfbba9111d171458103d82c4ecda3 (patch) | |
| tree | 6a15ca96da9879fc74d2a458362ff7237252f789 | |
| parent | d76d57b887b4bbc594ecae0b88bf5227786d1b63 (diff) | |
| download | php-git-def30dbde2edfbba9111d171458103d82c4ecda3.tar.gz | |
Avoid memory leak when creating paged control value
| -rw-r--r-- | ext/ldap/ldap.c | 11 |
1 files changed, 4 insertions, 7 deletions
diff --git a/ext/ldap/ldap.c b/ext/ldap/ldap.c index 8e2bfaba31..5f5c4ce6e1 100644 --- a/ext/ldap/ldap.c +++ b/ext/ldap/ldap.c @@ -270,25 +270,22 @@ static int _php_ldap_control_from_array(LDAP *ld, LDAPControl** ctrl, zval* arra } else if (strcmp(control_oid, LDAP_CONTROL_PAGEDRESULTS) == 0) { zval* tmp; int pagesize = 1; - struct berval *cookie = NULL; + struct berval cookie = { 0, NULL }; if ((tmp = zend_hash_str_find(Z_ARRVAL_P(val), "size", sizeof("size") - 1)) != NULL) { convert_to_long_ex(tmp); pagesize = Z_LVAL_P(tmp); } if ((tmp = zend_hash_str_find(Z_ARRVAL_P(val), "cookie", sizeof("cookie") - 1)) != NULL) { convert_to_string_ex(tmp); - cookie = ber_memalloc(sizeof * cookie); - if (cookie != NULL) { - cookie->bv_val = Z_STRVAL_P(tmp); - cookie->bv_len = Z_STRLEN_P(tmp); - } + cookie.bv_val = Z_STRVAL_P(tmp); + cookie.bv_len = Z_STRLEN_P(tmp); } control_value = ber_memalloc(sizeof * control_value); if (control_value == NULL) { rc = -1; php_error_docref(NULL, E_WARNING, "Failed to allocate control value"); } else { - rc = ldap_create_page_control_value(ld, pagesize, cookie, control_value); + rc = ldap_create_page_control_value(ld, pagesize, &cookie, control_value); if (rc != LDAP_SUCCESS) { php_error_docref(NULL, E_WARNING, "Failed to create paged result control value: %s (%d)", ldap_err2string(rc), rc); } |
