diff --git a/NEWS b/NEWS index 3cd0dcfc86d6..8e197ef0ac68 100644 --- a/NEWS +++ b/NEWS @@ -34,6 +34,8 @@ PHP NEWS (Ilia Alshanetsky) . Fixed bug GH-25195 (smm_shared_globals left dangling without an SHM backend). (Lazizbek Ergashev) + . Fixed heap corruption on shutdown of a Windows process that fell back to + the file cache. (Kamil Tekiela) - SOAP: . Fixed bug GH-25267 (NULL dereference in to_xml_any() with integer key). diff --git a/ext/opcache/ZendAccelerator.c b/ext/opcache/ZendAccelerator.c index c1248404270d..f606d1c23ccb 100644 --- a/ext/opcache/ZendAccelerator.c +++ b/ext/opcache/ZendAccelerator.c @@ -3549,7 +3549,13 @@ void accel_shutdown(void) orig_post_shutdown_cb = zend_post_shutdown_cb; zend_post_shutdown_cb = accel_post_shutdown; } else { - free(accel_shared_globals); +#if ENABLE_FILE_CACHE_FALLBACK + /* A fallback process maps accel_shared_globals from SHM; it did not allocate it. */ + if (!fallback_process) +#endif + { + free(accel_shared_globals); + } } zend_compile_file = accelerator_orig_compile_file; diff --git a/ext/opcache/tests/file_cache_fallback_win32.phpt b/ext/opcache/tests/file_cache_fallback_win32.phpt new file mode 100644 index 000000000000..07b5d01a6cd8 --- /dev/null +++ b/ext/opcache/tests/file_cache_fallback_win32.phpt @@ -0,0 +1,70 @@ +--TEST-- +Shutdown of a process that fell back to the file cache must not free the SHM globals +--EXTENSIONS-- +opcache +--INI-- +opcache.enable=1 +opcache.enable_cli=1 +opcache.file_cache_only=0 +--SKIPIF-- + +--FILE-- + ['pipe', 'w'], 2 => ['pipe', 'w']], $pipes, null, $env); +echo stream_get_contents($pipes[1]); +echo stream_get_contents($pipes[2]); +printf("exit code: 0x%08X\n", proc_close($proc) & 0xFFFFFFFF); +?> +--CLEAN-- +isDir() ? @rmdir($f->getPathname()) : @unlink($f->getPathname()); +} +@rmdir($base); +?> +--EXPECT-- +bool(true) +exit code: 0x00000000 diff --git a/ext/opcache/tests/gh18417.phpt b/ext/opcache/tests/gh18417.phpt index f4f430827b3a..65a5eaf23268 100644 --- a/ext/opcache/tests/gh18417.phpt +++ b/ext/opcache/tests/gh18417.phpt @@ -1,11 +1,14 @@ --TEST-- GH-18417 (Windows SHM reattachment fails when increasing memory_consumption or jit_buffer_size) +--EXTENSIONS-- +opcache +--INI-- +opcache.enable=1 +opcache.enable_cli=1 +opcache.file_cache_only=0 --SKIPIF-- --FILE--