diff --git a/ext/opcache/ZendAccelerator.c b/ext/opcache/ZendAccelerator.c index fb886d39e60ac..66c10021442ad 100644 --- a/ext/opcache/ZendAccelerator.c +++ b/ext/opcache/ZendAccelerator.c @@ -2153,7 +2153,10 @@ zend_op_array *persistent_compile_file(zend_file_handle *file_handle, int type) */ from_shared_memory = false; if (persistent_script) { + /* See GH-17246: we disable GC so that user code cannot be executed during the optimizer run. */ + bool orig_gc_state = gc_enable(false); persistent_script = cache_script_in_shared_memory(persistent_script, key, &from_shared_memory); + gc_enable(orig_gc_state); } /* Caching is disabled, returning op_array; diff --git a/ext/opcache/tests/jit/gh17246.inc b/ext/opcache/tests/jit/gh17246.inc new file mode 100644 index 0000000000000..f9e7d78fc165a --- /dev/null +++ b/ext/opcache/tests/jit/gh17246.inc @@ -0,0 +1,8 @@ +field = function() {}; + } + + public function __destruct() + { + // Necessary because we need to invoke tracing JIT during destruction + } +} + +for ($i = 0; $i < 10000; ++$i) { + $obj = new Test(); +} + +require __DIR__.'/gh17246.inc'; + +?> +--EXPECTF-- +Fatal error: Uncaught Error: Class "NonExistentClass" not found in %s:%d +Stack trace: +#0 %s(%d): require() +#1 {main} + thrown in %s on line %d