From f1ce44d1cbb23fd1984d36ce7b69aa34e6fc04d1 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Thu, 15 Apr 2021 16:21:17 +0200 Subject: [PATCH] Fix static variables in main script with file cache If the script will be cached in SHM (!corrupted), then we cannot allocate the static variables on the arena. Instead do the same thing we do during normal persistence and allocate a map ptr slot. --- ext/opcache/zend_file_cache.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/ext/opcache/zend_file_cache.c b/ext/opcache/zend_file_cache.c index 6662bdf7376..f138163ae17 100644 --- a/ext/opcache/zend_file_cache.c +++ b/ext/opcache/zend_file_cache.c @@ -1244,15 +1244,17 @@ static void zend_file_cache_unserialize_op_array(zend_op_array *op_arr zend_persistent_script *script, void *buf) { - if (!(script->corrupted) - && op_array != &script->script.main_op_array) { - op_array->fn_flags |= ZEND_ACC_IMMUTABLE; + if (!script->corrupted) { + if (op_array != &script->script.main_op_array) { + op_array->fn_flags |= ZEND_ACC_IMMUTABLE; + ZEND_MAP_PTR_NEW(op_array->run_time_cache); + } else { + ZEND_ASSERT(!(op_array->fn_flags & ZEND_ACC_IMMUTABLE)); + ZEND_MAP_PTR_INIT(op_array->run_time_cache, NULL); + } if (op_array->static_variables) { ZEND_MAP_PTR_NEW(op_array->static_variables_ptr); - } else { - ZEND_MAP_PTR_INIT(op_array->static_variables_ptr, NULL); } - ZEND_MAP_PTR_NEW(op_array->run_time_cache); } else { op_array->fn_flags &= ~ZEND_ACC_IMMUTABLE; if (op_array->static_variables) {