From 920fd04a37f60c01e5be1585bbba55ea9edda893 Mon Sep 17 00:00:00 2001 From: David Carlier Date: Sat, 24 May 2025 21:54:48 +0100 Subject: [PATCH 1/2] ext/mbstring: mb_ereg*_replace fix leak on failed callback. --- ext/mbstring/php_mbregex.c | 1 + 1 file changed, 1 insertion(+) diff --git a/ext/mbstring/php_mbregex.c b/ext/mbstring/php_mbregex.c index e1a5a10c39938..3322e8045416c 100644 --- a/ext/mbstring/php_mbregex.c +++ b/ext/mbstring/php_mbregex.c @@ -1109,6 +1109,7 @@ static void _php_mb_regex_ereg_replace_exec(INTERNAL_FUNCTION_PARAMETERS, OnigOp } else { if (!EG(exception)) { zend_throw_error(NULL, "Unable to call custom replacement function"); + onig_region_free(regs, 1); zval_ptr_dtor(&subpats); RETURN_THROWS(); } From d84273a1f635b8e931d7e3cdae581c2f9943b080 Mon Sep 17 00:00:00 2001 From: David Carlier Date: Sun, 25 May 2025 10:05:01 +0100 Subject: [PATCH 2/2] change from review --- ext/mbstring/php_mbregex.c | 7 ------- 1 file changed, 7 deletions(-) diff --git a/ext/mbstring/php_mbregex.c b/ext/mbstring/php_mbregex.c index 3322e8045416c..08db861f564ec 100644 --- a/ext/mbstring/php_mbregex.c +++ b/ext/mbstring/php_mbregex.c @@ -1106,13 +1106,6 @@ static void _php_mb_regex_ereg_replace_exec(INTERNAL_FUNCTION_PARAMETERS, OnigOp smart_str_appendl(&out_buf, Z_STRVAL(retval), Z_STRLEN(retval)); smart_str_free(&eval_buf); zval_ptr_dtor(&retval); - } else { - if (!EG(exception)) { - zend_throw_error(NULL, "Unable to call custom replacement function"); - onig_region_free(regs, 1); - zval_ptr_dtor(&subpats); - RETURN_THROWS(); - } } zval_ptr_dtor(&subpats); }