Skip to content

Commit

Permalink
Fixed bug #76846
Browse files Browse the repository at this point in the history
  • Loading branch information
nikic committed Sep 28, 2018
1 parent b5d0eb4 commit 45cdcb2
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
2 changes: 2 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ PHP NEWS
- Core:
. Fixed bug #76901 (method_exists on SPL iterator passthrough method corrupts
memory). (Nikita)
. Fixed bug #76846 (Segfault in shutdown function after memory limit error).
(Nikita)

- CURL:
. Fixed bug #76480 (Use curl_multi_wait() so that timeouts are respected).
Expand Down
27 changes: 27 additions & 0 deletions Zend/tests/bug76846.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
--TEST--
Bug #76846: Segfault in shutdown function after memory limit error
--INI--
memory_limit=33M
--SKIPIF--
<?php
$zend_mm_enabled = getenv("USE_ZEND_ALLOC");
if ($zend_mm_enabled === "0") {
die("skip Zend MM disabled");
}
?>
--FILE--
<?php

register_shutdown_function(function() {
new stdClass;
});

$ary = [];
while (true) {
$ary[] = new stdClass;
}

?>
--EXPECTF--
Fatal error: Allowed memory size of %d bytes exhausted at %s:%d (tried to allocate %d bytes) in %s on line %d
%A
6 changes: 4 additions & 2 deletions Zend/zend_objects_API.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,10 @@ ZEND_API void zend_objects_store_put(zend_object *object)
EG(objects_store).free_list_head = GET_OBJ_BUCKET_NUMBER(EG(objects_store).object_buckets[handle]);
} else {
if (EG(objects_store).top == EG(objects_store).size) {
EG(objects_store).size <<= 1;
EG(objects_store).object_buckets = (zend_object **) erealloc(EG(objects_store).object_buckets, EG(objects_store).size * sizeof(zend_object*));
uint32_t new_size = 2 * EG(objects_store).size;
EG(objects_store).object_buckets = (zend_object **) erealloc(EG(objects_store).object_buckets, new_size * sizeof(zend_object*));
/* Assign size after realloc, in case it fails */
EG(objects_store).size = new_size;
}
handle = EG(objects_store).top++;
}
Expand Down

0 comments on commit 45cdcb2

Please sign in to comment.