Skip to content

Commit 60a7e60

Browse files
committed
Fixed bug #72530
For objects with destructors, we will now only call the destructor in the initial GC run, and remove any nested data. The object is marked purple so it will be considered a root for the next GC run, at which point it will be fully destroyed, if possible. GC counts change on a number of tests, as the objects now get destroyed later.
1 parent fdfc7ea commit 60a7e60

File tree

11 files changed

+100
-46
lines changed

11 files changed

+100
-46
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ PHP NEWS
77
(Nikita)
88
. Fixed bug #78406 (Broken file includes with user-defined stream filters).
99
(Nikita)
10+
. Fixed bug #72530 (Use After Free in GC with Certain Destructors). (Nikita)
1011

1112
- Date:
1213
. Fixed bug #78383 (Casting a DateTime to array no longer returns its

Zend/tests/bug71818.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class MemoryLeak
1919
private $things = [];
2020
}
2121

22-
ini_set('memory_limit', '10M');
22+
ini_set('memory_limit', '20M');
2323

2424
for ($i = 0; $i < 100000; ++$i) {
2525
$obj = new MemoryLeak();

Zend/tests/bug72530.phpt

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
--TEST--
2+
Bug #72530: Use After Free in GC with Certain Destructors
3+
--FILE--
4+
<?php
5+
6+
class ryat {
7+
var $ryat;
8+
var $chtg;
9+
10+
function __destruct() {
11+
$this->chtg = $this->ryat;
12+
$this->ryat = 1;
13+
}
14+
}
15+
16+
$o = new ryat;
17+
$o->ryat = $o;
18+
$x =& $o->chtg;
19+
20+
unset($o);
21+
gc_collect_cycles();
22+
var_dump($x);
23+
24+
?>
25+
--EXPECT--
26+
object(ryat)#1 (2) {
27+
["ryat"]=>
28+
int(1)
29+
["chtg"]=>
30+
*RECURSION*
31+
}

Zend/tests/gc_011.phpt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ $a->a = $a;
1515
var_dump($a);
1616
unset($a);
1717
var_dump(gc_collect_cycles());
18+
var_dump(gc_collect_cycles());
1819
echo "ok\n"
1920
?>
2021
--EXPECTF--
@@ -23,5 +24,6 @@ object(Foo)#%d (1) {
2324
*RECURSION*
2425
}
2526
__destruct
27+
int(0)
2628
int(1)
2729
ok

Zend/tests/gc_016.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,6 @@ echo "ok\n"
2323
?>
2424
--EXPECT--
2525
-> int(0)
26-
int(1)
27-
int(1)
26+
int(0)
27+
int(2)
2828
ok

Zend/tests/gc_017.phpt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,13 @@ unset($a);
3232
unset($b);
3333
unset($c);
3434
var_dump(gc_collect_cycles());
35+
var_dump(gc_collect_cycles());
3536
echo "ok\n"
3637
?>
3738
--EXPECTF--
3839
string(1) "%s"
3940
string(1) "%s"
4041
string(1) "%s"
41-
int(4)
42+
int(0)
43+
int(1)
4244
ok

Zend/tests/gc_028.phpt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ $bar->foo = $foo;
2828
unset($foo);
2929
unset($bar);
3030
var_dump(gc_collect_cycles());
31+
var_dump(gc_collect_cycles());
3132
?>
3233
--EXPECT--
33-
int(2)
34+
int(0)
35+
int(1)

Zend/tests/gc_029.phpt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ $bar->foo = $foo;
3030
unset($foo);
3131
unset($bar);
3232
var_dump(gc_collect_cycles());
33+
var_dump(gc_collect_cycles());
3334
?>
34-
--EXPECTREGEX--
35-
int\([23]\)
35+
--EXPECT--
36+
int(0)
37+
int(1)

Zend/tests/gc_035.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,5 @@ var_dump(gc_collect_cycles());
2222
var_dump(gc_collect_cycles());
2323
--EXPECT--
2424
int(0)
25-
int(2)
2625
int(0)
26+
int(2)

Zend/tests/generators/bug76427.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@ var_dump(gc_collect_cycles());
2121

2222
?>
2323
--EXPECT--
24-
int(4)
24+
int(2)

0 commit comments

Comments
 (0)