Merge branch 'PHP-7.4' into PHP-8.0

* PHP-7.4:
  Fixed bug #81104
This commit is contained in:
Nikita Popov 2021-06-08 14:33:29 +02:00
commit d29f15ce5f
2 changed files with 35 additions and 2 deletions

View file

@ -272,8 +272,14 @@ static PHP_INI_MH(OnChangeMemoryLimit)
value = Z_L(1)<<30; /* effectively, no limit */
}
if (zend_set_memory_limit_ex(value) == FAILURE) {
zend_error(E_WARNING, "Failed to set memory limit to %zd bytes (Current memory usage is %zd bytes)", value, zend_memory_usage(true));
return FAILURE;
/* When the memory limit is reset to the original level during deactivation, we may be
* using more memory than the original limit while shutdown is still in progress.
* Ignore a failure for now, and set the memory limit when the memory manager has been
* shut down and the minimal amount of memory is used. */
if (stage != ZEND_INI_STAGE_DEACTIVATE) {
zend_error(E_WARNING, "Failed to set memory limit to %zd bytes (Current memory usage is %zd bytes)", value, zend_memory_usage(true));
return FAILURE;
}
}
PG(memory_limit) = value;
return SUCCESS;
@ -1849,6 +1855,10 @@ void php_request_shutdown(void *dummy)
shutdown_memory_manager(CG(unclean_shutdown) || !report_memleaks, 0);
} zend_end_try();
/* Reset memory limit, as the reset during INI_STAGE_DEACTIVATE may have failed.
* At this point, no memory beyond a single chunk should be in use. */
zend_set_memory_limit(PG(memory_limit));
/* 16. Deactivate Zend signals */
#ifdef ZEND_SIGNALS
zend_signal_deactivate();