Skip to content

Commit 21bb33c

Browse files
committed
Fixed bug #68652 (segmentation fault in destructor)
1 parent 890195f commit 21bb33c

File tree

3 files changed

+50
-7
lines changed

3 files changed

+50
-7
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ PHP NEWS
22
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
33
?? ??? 2015, PHP 5.5.25
44

5+
- Core:
6+
. Fixed bug #68652 (segmentation fault in destructor). (Dmitry)
7+
58
- cURL:
69
. Fixed bug #68739 (Missing break / control flow). (Laruence)
710

Zend/tests/bug68652.phpt

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
--TEST--
2+
Bug #68652 (segmentation fault in destructor)
3+
--FILE--
4+
<?php
5+
class Foo {
6+
7+
private static $instance;
8+
public static function getInstance() {
9+
if (isset(self::$instance)) {
10+
return self::$instance;
11+
}
12+
return self::$instance = new self();
13+
}
14+
15+
public function __destruct() {
16+
Bar::getInstance();
17+
}
18+
}
19+
20+
class Bar {
21+
22+
private static $instance;
23+
public static function getInstance() {
24+
if (isset(self::$instance)) {
25+
return self::$instance;
26+
}
27+
return self::$instance = new self();
28+
}
29+
30+
public function __destruct() {
31+
Foo::getInstance();
32+
}
33+
}
34+
35+
36+
$foo = new Foo();
37+
?>
38+
--EXPECTF--
39+
Fatal error: Access to undeclared static property: Bar::$instance in %sbug68652.php on line %d
40+

Zend/zend_opcode.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -162,16 +162,16 @@ static inline void cleanup_user_class_data(zend_class_entry *ce TSRMLS_DC)
162162
zend_hash_apply(&ce->function_table, (apply_func_t) zend_cleanup_function_data_full TSRMLS_CC);
163163
}
164164
if (ce->static_members_table) {
165+
zval *static_members = ce->static_members_table;
166+
int count = ce->default_static_members_count;
165167
int i;
166168

167-
for (i = 0; i < ce->default_static_members_count; i++) {
168-
if (ce->static_members_table[i]) {
169-
zval *p = ce->static_members_table[i];
170-
ce->static_members_table[i] = NULL;
171-
zval_ptr_dtor(&p);
172-
}
169+
ce->default_static_members_count = 0;
170+
ce->default_static_members_table = ce->static_members_table = NULL;
171+
for (i = 0; i < count; i++) {
172+
zval_ptr_dtor(&static_members[i]);
173173
}
174-
ce->static_members_table = NULL;
174+
efree(static_members);
175175
}
176176
}
177177

0 commit comments

Comments
 (0)