Skip to content

Commit 1c35357

Browse files
committed
Merge branch 'PHP-7.1' into PHP-7.2
2 parents 5f29e3f + 45cdcb2 commit 1c35357

File tree

3 files changed

+33
-2
lines changed

3 files changed

+33
-2
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ PHP NEWS
1010
(Dmitry)
1111
. Fixed bug #76901 (method_exists on SPL iterator passthrough method corrupts
1212
memory). (Nikita)
13+
. Fixed bug #76846 (Segfault in shutdown function after memory limit error).
14+
(Nikita)
1315

1416
- CURL:
1517
. Fixed bug #76480 (Use curl_multi_wait() so that timeouts are respected).

Zend/tests/bug76846.phpt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
--TEST--
2+
Bug #76846: Segfault in shutdown function after memory limit error
3+
--INI--
4+
memory_limit=33M
5+
--SKIPIF--
6+
<?php
7+
$zend_mm_enabled = getenv("USE_ZEND_ALLOC");
8+
if ($zend_mm_enabled === "0") {
9+
die("skip Zend MM disabled");
10+
}
11+
?>
12+
--FILE--
13+
<?php
14+
15+
register_shutdown_function(function() {
16+
new stdClass;
17+
});
18+
19+
$ary = [];
20+
while (true) {
21+
$ary[] = new stdClass;
22+
}
23+
24+
?>
25+
--EXPECTF--
26+
Fatal error: Allowed memory size of %d bytes exhausted at %s:%d (tried to allocate %d bytes) in %s on line %d
27+
%A

Zend/zend_objects_API.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,10 @@ ZEND_API void zend_objects_store_put(zend_object *object)
141141
EG(objects_store).free_list_head = GET_OBJ_BUCKET_NUMBER(EG(objects_store).object_buckets[handle]);
142142
} else {
143143
if (EG(objects_store).top == EG(objects_store).size) {
144-
EG(objects_store).size <<= 1;
145-
EG(objects_store).object_buckets = (zend_object **) erealloc(EG(objects_store).object_buckets, EG(objects_store).size * sizeof(zend_object*));
144+
uint32_t new_size = 2 * EG(objects_store).size;
145+
EG(objects_store).object_buckets = (zend_object **) erealloc(EG(objects_store).object_buckets, new_size * sizeof(zend_object*));
146+
/* Assign size after realloc, in case it fails */
147+
EG(objects_store).size = new_size;
146148
}
147149
handle = EG(objects_store).top++;
148150
}

0 commit comments

Comments
 (0)