Skip to content

Commit 3a4ea6c

Browse files
pvandommelennikic
authored andcommitted
Don't automatically adjust memory_limit to 2M
As PHP has a minimum memory usage of 2M (size of allocator chunk), setting a limit below that value is not meaningful and will be automatically rounded up to the chunk size. Rather than doing this silently, show the newly introduced error message. The memory limit had to be increased to 2M for a number of tests. tests/lang/bug45392 has been marked as XFAIL. This old bugfix is not working as intended. The memory limit in main's `PG(memory_limit)` differs from the one in zend_alloc. In zend_alloc the `AG(mm_heap)->limit` is defined as `max(passed_value, ZEND_MM_CHUNK_SIZE)`. The check made in an unclean shutdown will never be true unless the memory limit is lower than ZEND_MM_CHUNK_SIZE, which happened to be the case in the test. https://bugs.php.net/bug.php?id=45392 fcc0fdd
1 parent 1aafed5 commit 3a4ea6c

File tree

6 files changed

+8
-9
lines changed

6 files changed

+8
-9
lines changed

Zend/tests/fibers/out-of-memory-in-fiber.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
--TEST--
22
Out of Memory in a fiber
33
--INI--
4-
memory_limit=10K
4+
memory_limit=2M
55
--SKIPIF--
66
<?php
77
if (getenv("USE_ZEND_ALLOC") === "0") {

Zend/tests/fibers/out-of-memory-in-nested-fiber.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
--TEST--
22
Out of Memory in a nested fiber
33
--INI--
4-
memory_limit=10K
4+
memory_limit=2M
55
--SKIPIF--
66
<?php
77
if (getenv("USE_ZEND_ALLOC") === "0") {

Zend/tests/fibers/out-of-memory-in-recursive-fiber.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
--TEST--
22
Out of Memory from recursive fiber creation
33
--INI--
4-
memory_limit=10K
4+
memory_limit=2M
55
--SKIPIF--
66
<?php
77
if (getenv("USE_ZEND_ALLOC") === "0") {

Zend/zend_alloc.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2661,9 +2661,6 @@ ZEND_API char* ZEND_FASTCALL zend_strndup(const char *s, size_t length)
26612661
ZEND_API zend_result zend_set_memory_limit(size_t memory_limit)
26622662
{
26632663
#if ZEND_MM_LIMIT
2664-
if (memory_limit < ZEND_MM_CHUNK_SIZE) {
2665-
memory_limit = ZEND_MM_CHUNK_SIZE;
2666-
}
26672664
if (UNEXPECTED(memory_limit < AG(mm_heap)->real_size)) {
26682665
return FAILURE;
26692666
}

ext/standard/tests/streams/bug78902.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
--TEST--
22
Bug #78902: Memory leak when using stream_filter_append
33
--INI--
4-
memory_limit=512k
4+
memory_limit=2M
55
--FILE--
66
<?php
77

88
/** create temporary file 2mb file */
99
$tmp_file_name = tempnam(sys_get_temp_dir(), 'test_');
1010
$fp = fopen($tmp_file_name, 'w+');
11-
$size = 1024 * 1024 * 2; // 2mb
11+
$size = 1024 * 1024 * 2; // 2mb, larger than the memory limit
1212
$chunk = 1024;
1313
while ($size > 0) {
1414
fputs($fp, str_pad('', min($chunk,$size)));

tests/lang/bug45392.phpt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
Bug #45392 (ob_start()/ob_end_clean() and memory_limit)
33
--INI--
44
display_errors=stderr
5+
--XFAIL--
6+
The issue has not yet been resolved.
57
--SKIPIF--
68
<?php
79
if (getenv("USE_ZEND_ALLOC") === "0") {
@@ -10,7 +12,7 @@ if (getenv("USE_ZEND_ALLOC") === "0") {
1012
--FILE--
1113
<?php
1214
echo __LINE__ . "\n";
13-
ini_set('memory_limit', 100);
15+
ini_set('memory_limit', "2M");
1416
ob_start();
1517
$i = 0;
1618
while($i++ < 5000) {

0 commit comments

Comments
 (0)