Skip to content

Commit da70576

Browse files
committed
Fix issues addressed during review
1 parent 9e42b57 commit da70576

File tree

2 files changed

+25
-21
lines changed

2 files changed

+25
-21
lines changed

main/main.c

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -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 */
366370
static 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

main/php_globals.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ struct _php_core_globals {
7272
zend_long serialize_precision;
7373

7474
zend_long memory_limit;
75-
zend_long max_memory_limit;
75+
zend_long max_memory_limit;
7676
zend_long max_input_time;
7777

7878
char *error_log;

0 commit comments

Comments
 (0)