@@ -318,11 +318,11 @@ static PHP_INI_MH(OnChangeMemoryLimit)
318318{
319319 size_t value ;
320320
321- if (new_value ) {
322- value = zend_ini_parse_uquantity_warn (new_value , entry -> name );
323- } else {
324- value = Z_L (1 ) << 30 ; /* effectively, no limit */
325- }
321+ if (new_value ) {
322+ value = zend_ini_parse_uquantity_warn (new_value , entry -> name );
323+ } else {
324+ value = Z_L (1 ) << 30 ; /* effectively, no limit */
325+ }
326326
327327 /* If max_memory_limit is not set to unlimited, verify change */
328328 if (PG (max_memory_limit ) != 0 && PG (max_memory_limit ) != -1 ) {
@@ -350,27 +350,31 @@ static PHP_INI_MH(OnChangeMemoryLimit)
350350 }
351351 }
352352
353- if (zend_set_memory_limit (value ) == FAILURE ) {
354- if (stage != ZEND_INI_STAGE_DEACTIVATE ) {
355- zend_error (E_WARNING , "Failed to set memory limit to %zd bytes (Current memory usage is %zd bytes)" , value , zend_memory_usage (true));
356- return FAILURE ;
357- }
358- }
353+ if (zend_set_memory_limit (value ) == FAILURE ) {
354+ /* When the memory limit is reset to the original level during deactivation, we may be
355+ * using more memory than the original limit while shutdown is still in progress.
356+ * Ignore a failure for now, and set the memory limit when the memory manager has been
357+ * shut down and the minimal amount of memory is used. */
358+ if (stage != ZEND_INI_STAGE_DEACTIVATE ) {
359+ zend_error (E_WARNING , "Failed to set memory limit to %zd bytes (Current memory usage is %zd bytes)" , value , zend_memory_usage (true));
360+ return FAILURE ;
361+ }
362+ }
359363
360- PG (memory_limit ) = value ;
361- return SUCCESS ;
364+ PG (memory_limit ) = value ;
365+ return SUCCESS ;
362366}
363367/* }}} */
364368
365369/* {{{ PHP_INI_MH */
366370static PHP_INI_MH (OnChangeMaxMemoryLimit )
367371{
368372 size_t value ;
369- if (new_value ) {
370- value = zend_ini_parse_uquantity_warn (new_value , entry -> name );
371- } else {
372- value = Z_L (1 ) << 30 ; /* effectively, no limit */
373- }
373+ if (new_value ) {
374+ value = zend_ini_parse_uquantity_warn (new_value , entry -> name );
375+ } else {
376+ value = Z_L (1 ) << 30 ; /* effectively, no limit */
377+ }
374378
375379 /* If new value is not unlimited, verify change */
376380 if (value != -1 ) {
@@ -394,8 +398,8 @@ static PHP_INI_MH(OnChangeMaxMemoryLimit)
394398 }
395399 }
396400
397- PG (max_memory_limit ) = value ;
398- return SUCCESS ;
401+ PG (max_memory_limit ) = value ;
402+ return SUCCESS ;
399403}
400404/* }}} */
401405
0 commit comments