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