Skip to content

Rerun of GC due to should_rerun_gc = 1 resets count variable, increasing buffer indefinitely #9265

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions Zend/tests/gc_045.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
--TEST--
GC 045: Total count persisted when GC is rerun due to destructor call
--INI--
zend.enable_gc=1
--FILE--
<?php
class GlobalData
{
public static Bar $bar;
}

class Value
{
public function __destruct()
{
new Bar();
}
}

class Bar
{
public function __construct()
{
GlobalData::$bar = $this;
}
}

class Foo
{
public Foo $selfRef;
public Value $val;

public function __construct(Value $val)
{
$this->val = $val;
$this->selfRef = $this;
}
}

for ($j = 0; $j < 10; $j++) {
for ($i = 0; $i < 3000; $i++) {
new Foo(new Value());
}
}

var_dump(gc_status());
?>
--EXPECT--
array(4) {
["runs"]=>
int(10)
["collected"]=>
int(25000)
["threshold"]=>
int(10001)
["roots"]=>
int(10000)
}
6 changes: 4 additions & 2 deletions Zend/zend_gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1469,12 +1469,13 @@ static void zend_gc_root_tmpvars(void);

ZEND_API int zend_gc_collect_cycles(void)
{
int count = 0;
int total_count = 0;
bool should_rerun_gc = 0;
bool did_rerun_gc = 0;

rerun_gc:
if (GC_G(num_roots)) {
int count;
gc_root_buffer *current, *last;
zend_refcounted *p;
uint32_t gc_flags = 0;
Expand Down Expand Up @@ -1652,6 +1653,7 @@ ZEND_API int zend_gc_collect_cycles(void)

GC_TRACE("Collection finished");
GC_G(collected) += count;
total_count += count;
GC_G(gc_active) = 0;
}

Expand All @@ -1668,7 +1670,7 @@ ZEND_API int zend_gc_collect_cycles(void)
finish:
zend_get_gc_buffer_release();
zend_gc_root_tmpvars();
return count;
return total_count;
}

ZEND_API void zend_gc_get_status(zend_gc_status *status)
Expand Down