From ffb440550c4ff7d4a8e47fbef82cb99a17ba36b6 Mon Sep 17 00:00:00 2001 From: Ilija Tovilo Date: Thu, 12 Sep 2024 22:32:23 +0200 Subject: [PATCH] Use APPLY_STOP in pcre_clean_cache() (GH-15839) Once num_clean has reached 0, we never remove any more elements anyway. Closes GH-15839 --- ext/pcre/php_pcre.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/ext/pcre/php_pcre.c b/ext/pcre/php_pcre.c index 6ad2c964cd4..2545320ea2f 100644 --- a/ext/pcre/php_pcre.c +++ b/ext/pcre/php_pcre.c @@ -494,8 +494,10 @@ static int pcre_clean_cache(zval *data, void *arg) pcre_cache_entry *pce = (pcre_cache_entry *) Z_PTR_P(data); int *num_clean = (int *)arg; - if (*num_clean > 0 && !pce->refcount) { - (*num_clean)--; + if (!pce->refcount) { + if (--(*num_clean) == 0) { + return ZEND_HASH_APPLY_REMOVE|ZEND_HASH_APPLY_STOP; + } return ZEND_HASH_APPLY_REMOVE; } else { return ZEND_HASH_APPLY_KEEP;