Skip to content

Commit 291d8db

Browse files
committed
Merge branch 'PHP-8.0'
* PHP-8.0: Fixed bug #81104
2 parents 703fcf0 + d29f15c commit 291d8db

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

Zend/tests/bug81104.phpt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
--TEST--
2+
Bug #81104: Warning: "Failed to set memory limit to ... bytes" emitted after exit in debug
3+
--INI--
4+
memory_limit=5M
5+
report_memleaks=0
6+
--FILE--
7+
<?php
8+
class X {
9+
public $x;
10+
public function __construct() { $this->x = [$this]; }
11+
}
12+
gc_disable();
13+
ini_set('memory_limit', '10M');
14+
$y = [];
15+
for ($i = 0; $i < 10000; $i++) {
16+
$y[] = new X();
17+
}
18+
$y[0]->y = &$y;
19+
20+
?>
21+
===DONE===
22+
--EXPECT--
23+
===DONE===

main/main.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,8 +273,14 @@ static PHP_INI_MH(OnChangeMemoryLimit)
273273
value = Z_L(1)<<30; /* effectively, no limit */
274274
}
275275
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+
}
278284
}
279285
PG(memory_limit) = value;
280286
return SUCCESS;
@@ -1850,6 +1856,10 @@ void php_request_shutdown(void *dummy)
18501856
shutdown_memory_manager(CG(unclean_shutdown) || !report_memleaks, 0);
18511857
} zend_end_try();
18521858

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+
18531863
/* 16. Deactivate Zend signals */
18541864
#ifdef ZEND_SIGNALS
18551865
zend_signal_deactivate();

0 commit comments

Comments
 (0)