Skip to content

Commit 7da6498

Browse files
committed
Fixed bug #60598 (cli/apache sapi segfault on objects manipulation)
1 parent dfc6feb commit 7da6498

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ PHP NEWS
33
?? ??? 2013, PHP 5.4.20
44

55
- Core:
6+
. Fixed bug #60598 (cli/apache sapi segfault on objects manipulation).
7+
(Laruence)
68
. Fixed bug #65579 (Using traits with get_class_methods causes segfault).
79
(Adam)
810
. Fixed bug #65490 (Duplicate calls to get lineno & filename for

Zend/tests/bug60598.phpt

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
--TEST--
2+
Bug #60598 (cli/apache sapi segfault on objects manipulation)
3+
--FILE--
4+
<?php
5+
define('OBJECT_COUNT', 10000);
6+
7+
$containers = array();
8+
9+
class Object {
10+
protected $_guid = 0;
11+
public function __construct() {
12+
global $containers;
13+
$this->guid = 1;
14+
$containers[spl_object_hash($this)] = $this;
15+
}
16+
public function __destruct() {
17+
global $containers;
18+
$containers[spl_object_hash($this)] = NULL;
19+
}
20+
}
21+
22+
for ($i = 0; $i < OBJECT_COUNT; ++$i) {
23+
new Object();
24+
}
25+
26+
// You probably won't see this because of the "zend_mm_heap corrupted"
27+
?>
28+
If you see this, try to increase OBJECT_COUNT to 100,000
29+
--EXPECT--
30+
If you see this, try to increase OBJECT_COUNT to 100,000

Zend/zend_objects_API.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ ZEND_API void zend_objects_store_call_destructors(zend_objects_store *objects TS
5757
obj->dtor(obj->object, i TSRMLS_CC);
5858
obj = &objects->object_buckets[i].bucket.obj;
5959
obj->refcount--;
60+
61+
if (obj->refcount == 0) {
62+
/* in case gc_collect_cycle is triggered before free_storage */
63+
GC_REMOVE_ZOBJ_FROM_BUFFER(obj);
64+
}
6065
}
6166
}
6267
}

0 commit comments

Comments
 (0)