Skip to content

Fix GH-16577: EG(strtod_state).freelist leaks with opcache.preload #16602

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions ext/opcache/ZendAccelerator.c
Original file line number Diff line number Diff line change
Expand Up @@ -4462,6 +4462,12 @@ static zend_result accel_preload(const char *config, bool in_child)
/* Release stored values to avoid dangling pointers */
zend_shutdown_executor_values(/* fast_shutdown */ false);

/* On ZTS we execute `executor_globals_ctor` which reset the freelist and p5s pointers, while on NTS we don't.
* We have to clean up the memory before the actual request takes place to avoid a memory leak. */
#ifdef ZTS
zend_shutdown_strtod();
#endif

/* We don't want to preload constants.
* Check that zend_shutdown_executor_values() also destroys constants. */
ZEND_ASSERT(zend_hash_num_elements(EG(zend_constants)) == EG(persistent_constants_count));
Expand Down
2 changes: 2 additions & 0 deletions ext/opcache/tests/gh16577.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?php
var_dump(1.5);
20 changes: 20 additions & 0 deletions ext/opcache/tests/gh16577.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
--TEST--
GH-16577 (EG(strtod_state).freelist leaks with opcache.preload)
--INI--
opcache.enable=1
opcache.enable_cli=1
opcache.optimization_level=-1
opcache.preload={PWD}/gh16577.inc
--EXTENSIONS--
opcache
--SKIPIF--
<?php
if (PHP_OS_FAMILY == 'Windows') die('skip Preloading is not supported on Windows');
?>
--FILE--
<?php
echo "Done\n";
?>
--EXPECT--
float(1.5)
Done