Avoid unnecessary reference-counting on strings.

This commit is contained in:
Dmitry Stogov 2017-11-16 17:09:32 +03:00
parent ce18738a30
commit ccc12b82da
29 changed files with 636 additions and 510 deletions

View file

@ -2393,9 +2393,10 @@ static int _php_curl_setopt(php_curl *ch, zend_long option, zval *zvalue) /* {{{
case CURLOPT_DEFAULT_PROTOCOL:
#endif
{
zend_string *str = zval_get_string(zvalue);
zend_string *tmp_str;
zend_string *str = zval_get_tmp_string(zvalue, &tmp_str);
int ret = php_curl_option_str(ch, option, ZSTR_VAL(str), ZSTR_LEN(str), 0);
zend_string_release(str);
zend_tmp_string_release(tmp_str);
return ret;
}
@ -2427,9 +2428,10 @@ static int _php_curl_setopt(php_curl *ch, zend_long option, zval *zvalue) /* {{{
if (Z_ISNULL_P(zvalue)) {
error = curl_easy_setopt(ch->cp, option, NULL);
} else {
zend_string *str = zval_get_string(zvalue);
zend_string *tmp_str;
zend_string *str = zval_get_tmp_string(zvalue, &tmp_str);
int ret = php_curl_option_str(ch, option, ZSTR_VAL(str), ZSTR_LEN(str), 0);
zend_string_release(str);
zend_tmp_string_release(tmp_str);
return ret;
}
break;
@ -2438,18 +2440,20 @@ static int _php_curl_setopt(php_curl *ch, zend_long option, zval *zvalue) /* {{{
/* Curl private option */
case CURLOPT_PRIVATE:
{
zend_string *str = zval_get_string(zvalue);
zend_string *tmp_str;
zend_string *str = zval_get_tmp_string(zvalue, &tmp_str);
int ret = php_curl_option_str(ch, option, ZSTR_VAL(str), ZSTR_LEN(str), 1);
zend_string_release(str);
zend_tmp_string_release(tmp_str);
return ret;
}
/* Curl url option */
case CURLOPT_URL:
{
zend_string *str = zval_get_string(zvalue);
zend_string *tmp_str;
zend_string *str = zval_get_tmp_string(zvalue, &tmp_str);
int ret = php_curl_option_url(ch, ZSTR_VAL(str), ZSTR_LEN(str));
zend_string_release(str);
zend_tmp_string_release(tmp_str);
return ret;
}
@ -2572,7 +2576,7 @@ static int _php_curl_setopt(php_curl *ch, zend_long option, zval *zvalue) /* {{{
{
zval *current;
HashTable *ph;
zend_string *val;
zend_string *val, *tmp_val;
struct curl_slist *slist = NULL;
ph = HASH_OF(zvalue);
@ -2624,9 +2628,9 @@ static int _php_curl_setopt(php_curl *ch, zend_long option, zval *zvalue) /* {{{
ZEND_HASH_FOREACH_VAL(ph, current) {
ZVAL_DEREF(current);
val = zval_get_string(current);
val = zval_get_tmp_string(current, &tmp_val);
slist = curl_slist_append(slist, ZSTR_VAL(val));
zend_string_release(val);
zend_tmp_string_release(tmp_val);
if (!slist) {
php_error_docref(NULL, E_WARNING, "Could not build curl_slist");
return 1;
@ -2687,7 +2691,7 @@ static int _php_curl_setopt(php_curl *ch, zend_long option, zval *zvalue) /* {{{
}
ZEND_HASH_FOREACH_KEY_VAL(postfields, num_key, string_key, current) {
zend_string *postval;
zend_string *postval, *tmp_postval;
/* Pretend we have a string_key here */
if (!string_key) {
string_key = zend_long_to_str(num_key);
@ -2737,7 +2741,7 @@ static int _php_curl_setopt(php_curl *ch, zend_long option, zval *zvalue) /* {{{
continue;
}
postval = zval_get_string(current);
postval = zval_get_tmp_string(current, &tmp_postval);
/* The arguments after _NAMELENGTH and _CONTENTSLENGTH
* must be explicitly cast to long in curl_formadd
@ -2753,7 +2757,7 @@ static int _php_curl_setopt(php_curl *ch, zend_long option, zval *zvalue) /* {{{
/* Not nice to convert between enums but we only have place for one error type */
error = (CURLcode)form_error;
}
zend_string_release(postval);
zend_tmp_string_release(tmp_postval);
zend_string_release(string_key);
} ZEND_HASH_FOREACH_END();
@ -2769,21 +2773,23 @@ static int _php_curl_setopt(php_curl *ch, zend_long option, zval *zvalue) /* {{{
error = curl_easy_setopt(ch->cp, CURLOPT_HTTPPOST, first);
} else {
#if LIBCURL_VERSION_NUM >= 0x071101
zend_string *str = zval_get_string(zvalue);
zend_string *tmp_str;
zend_string *str = zval_get_tmp_string(zvalue, &tmp_str);
/* with curl 7.17.0 and later, we can use COPYPOSTFIELDS, but we have to provide size before */
error = curl_easy_setopt(ch->cp, CURLOPT_POSTFIELDSIZE, ZSTR_LEN(str));
error = curl_easy_setopt(ch->cp, CURLOPT_COPYPOSTFIELDS, ZSTR_VAL(str));
zend_string_release(str);
zend_tmp_string_release(tmp_str);
#else
char *post = NULL;
zend_string *str = zval_get_string(zvalue);
zend_string *tmp_str;
zend_string *str = zval_get_tmp_string(zvalue, &tmp_str);
post = estrndup(ZSTR_VAL(str), ZSTR_LEN(str));
zend_llist_add_element(&ch->to_free->str, &post);
curl_easy_setopt(ch->cp, CURLOPT_POSTFIELDS, post);
error = curl_easy_setopt(ch->cp, CURLOPT_POSTFIELDSIZE, ZSTR_LEN(str));
zend_string_release(str);
zend_tmp_string_release(tmp_str);
#endif
}
break;
@ -2873,16 +2879,17 @@ static int _php_curl_setopt(php_curl *ch, zend_long option, zval *zvalue) /* {{{
case CURLOPT_SSH_KNOWNHOSTS:
#endif
{
zend_string *str = zval_get_string(zvalue);
zend_string *tmp_str;
zend_string *str = zval_get_tmp_string(zvalue, &tmp_str);
int ret;
if (ZSTR_LEN(str) && php_check_open_basedir(ZSTR_VAL(str))) {
zend_string_release(str);
zend_tmp_string_release(tmp_str);
return FAILURE;
}
ret = php_curl_option_str(ch, option, ZSTR_VAL(str), ZSTR_LEN(str), 0);
zend_string_release(str);
zend_tmp_string_release(tmp_str);
return ret;
}