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