summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikita Popov <nikita.ppv@gmail.com>2018-09-18 12:46:13 +0200
committerNikita Popov <nikita.ppv@gmail.com>2018-09-18 12:46:30 +0200
commite947bcaf3925ffba1b214399ad32c319ba038c55 (patch)
tree121427802d7442254aaa95a2ff33127f0a3d8239
parent208f5b0941c1a6b04a15cee978b1f0fa93cb1573 (diff)
downloadphp-git-e947bcaf3925ffba1b214399ad32c319ba038c55.tar.gz
Simplify buffer management in php_intl_idn_to_46()
Instead of manually tracking how/whether the buffer is used, make use of the string refcount.
-rw-r--r--ext/intl/idn/idn.c19
1 files changed, 3 insertions, 16 deletions
diff --git a/ext/intl/idn/idn.c b/ext/intl/idn/idn.c
index 1b73e2d4e6..305a944cce 100644
--- a/ext/intl/idn/idn.c
+++ b/ext/intl/idn/idn.c
@@ -128,7 +128,6 @@ static void php_intl_idn_to_46(INTERNAL_FUNCTION_PARAMETERS,
int32_t len;
zend_string *buffer;
UIDNAInfo info = UIDNA_INFO_INITIALIZER;
- int buffer_used = 0;
uts46 = uidna_openUTS46(option, &status);
if (php_intl_idn_check_status(status, "failed to open UIDNA instance") == FAILURE) {
@@ -161,31 +160,19 @@ static void php_intl_idn_to_46(INTERNAL_FUNCTION_PARAMETERS,
ZSTR_LEN(buffer) = len;
if (info.errors == 0) {
- RETVAL_STR(buffer);
- buffer_used = 1;
+ RETVAL_STR_COPY(buffer);
} else {
RETVAL_FALSE;
}
if (idna_info) {
- if (buffer_used) { /* used in return_value then */
- zval_addref_p(return_value);
- add_assoc_zval_ex(idna_info, "result", sizeof("result")-1, return_value);
- } else {
- zval zv;
- ZVAL_NEW_STR(&zv, buffer);
- buffer_used = 1;
- add_assoc_zval_ex(idna_info, "result", sizeof("result")-1, &zv);
- }
+ add_assoc_str_ex(idna_info, "result", sizeof("result")-1, zend_string_copy(buffer));
add_assoc_bool_ex(idna_info, "isTransitionalDifferent",
sizeof("isTransitionalDifferent")-1, info.isTransitionalDifferent);
add_assoc_long_ex(idna_info, "errors", sizeof("errors")-1, (zend_long)info.errors);
}
- if (!buffer_used) {
- zend_string_efree(buffer);
- }
-
+ zend_string_release(buffer);
uidna_close(uts46);
}