From 7ba434596afaf534d353ac2ff9b998c4ef7ec0e4 Mon Sep 17 00:00:00 2001 From: Niels Dossche <7771979+nielsdos@users.noreply.github.com> Date: Sat, 22 Feb 2025 16:30:13 +0100 Subject: [PATCH] Avoid unnecessary string refcounting in ext/pcre --- ext/pcre/php_pcre.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/ext/pcre/php_pcre.c b/ext/pcre/php_pcre.c index 339ed2390413d..a2a577a6745a0 100644 --- a/ext/pcre/php_pcre.c +++ b/ext/pcre/php_pcre.c @@ -1563,9 +1563,12 @@ static zend_string *preg_do_repl_func(zend_fcall_info *fci, zend_fcall_info_cach fci->params = &arg; zend_call_function(fci, fcc); zval_ptr_dtor(&arg); + if (EXPECTED(Z_TYPE(retval) == IS_STRING)) { + return Z_STR(retval); + } /* No Exception has occurred */ - if (EXPECTED(Z_TYPE(retval) != IS_UNDEF)) { - result_str = zval_try_get_string(&retval); + else if (EXPECTED(Z_TYPE(retval) != IS_UNDEF)) { + result_str = zval_try_get_string_func(&retval); } zval_ptr_dtor(&retval);