From 9278be148e751bc6d2107f4df667f6a6de4daa66 Mon Sep 17 00:00:00 2001 From: Anatol Belski Date: Sun, 9 Sep 2018 10:38:36 +0200 Subject: Fix memory leak in pcre cache --- ext/pcre/php_pcre.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'ext/pcre/php_pcre.c') diff --git a/ext/pcre/php_pcre.c b/ext/pcre/php_pcre.c index 3910b41fea..7aa879d26d 100644 --- a/ext/pcre/php_pcre.c +++ b/ext/pcre/php_pcre.c @@ -549,6 +549,7 @@ PHPAPI pcre_cache_entry* pcre_get_compiled_regex_cache(zend_string *regex) pcre_cache_entry new_entry; int rc; zend_string *key; + pcre_cache_entry *ret; #if HAVE_SETLOCALE if (BG(locale_string) && @@ -843,15 +844,19 @@ PHPAPI pcre_cache_entry* pcre_get_compiled_regex_cache(zend_string *regex) zend_string *str = zend_string_init(ZSTR_VAL(key), ZSTR_LEN(key), 1); GC_MAKE_PERSISTENT_LOCAL(str); + #if HAVE_SETLOCALE if (key != regex) { zend_string_release_ex(key, 0); } #endif - key = str; + ret = zend_hash_add_new_mem(&PCRE_G(pcre_cache), str, &new_entry, sizeof(pcre_cache_entry)); + zend_string_release(str); + } else { + ret = zend_hash_add_new_mem(&PCRE_G(pcre_cache), key, &new_entry, sizeof(pcre_cache_entry)); } - return zend_hash_add_new_mem(&PCRE_G(pcre_cache), key, &new_entry, sizeof(pcre_cache_entry)); + return ret; } /* }}} */ -- cgit v1.2.1