Skip to content

Commit 45cdcb2

Browse files
committed
Fixed bug #76846
1 parent b5d0eb4 commit 45cdcb2

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
@@ -5,6 +5,8 @@ PHP NEWS
55
- Core:
66
. Fixed bug #76901 (method_exists on SPL iterator passthrough method corrupts
77
memory). (Nikita)
8+
. Fixed bug #76846 (Segfault in shutdown function after memory limit error).
9+
(Nikita)
810

911
- CURL:
1012
. 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
@@ -116,8 +116,10 @@ ZEND_API void zend_objects_store_put(zend_object *object)
116116
EG(objects_store).free_list_head = GET_OBJ_BUCKET_NUMBER(EG(objects_store).object_buckets[handle]);
117117
} else {
118118
if (EG(objects_store).top == EG(objects_store).size) {
119-
EG(objects_store).size <<= 1;
120-
EG(objects_store).object_buckets = (zend_object **) erealloc(EG(objects_store).object_buckets, EG(objects_store).size * sizeof(zend_object*));
119+
uint32_t new_size = 2 * EG(objects_store).size;
120+
EG(objects_store).object_buckets = (zend_object **) erealloc(EG(objects_store).object_buckets, new_size * sizeof(zend_object*));
121+
/* Assign size after realloc, in case it fails */
122+
EG(objects_store).size = new_size;
121123
}
122124
handle = EG(objects_store).top++;
123125
}

0 commit comments

Comments
 (0)