Skip to content

Commit 72b7d99

Browse files
committed
Remove removed nested data from GC count
1 parent f0f3fe0 commit 72b7d99

File tree

2 files changed

+18
-14
lines changed

2 files changed

+18
-14
lines changed

Zend/tests/gc_041.phpt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@ $o->nested[] =& $o->nested;
1818
$o->ryat = $o;
1919
$x =& $o->chtg;
2020
unset($o);
21-
gc_collect_cycles();
21+
var_dump(gc_collect_cycles());
2222
var_dump($x);
2323
?>
2424
--EXPECT--
25+
int(0)
2526
object(ryat)#1 (3) {
2627
["ryat"]=>
2728
*RECURSION*
@@ -32,4 +33,4 @@ object(ryat)#1 (3) {
3233
[0]=>
3334
*RECURSION*
3435
}
35-
}
36+
}

Zend/zend_gc.c

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1318,11 +1318,12 @@ static int gc_collect_roots(uint32_t *flags, gc_stack *stack)
13181318
return count;
13191319
}
13201320

1321-
static void gc_remove_nested_data_from_buffer(zend_refcounted *ref, gc_root_buffer *root)
1321+
static int gc_remove_nested_data_from_buffer(zend_refcounted *ref, gc_root_buffer *root)
13221322
{
13231323
HashTable *ht = NULL;
13241324
Bucket *p, *end;
13251325
zval *zv;
1326+
int count = 0;
13261327

13271328
tail_call:
13281329
do {
@@ -1331,18 +1332,20 @@ static void gc_remove_nested_data_from_buffer(zend_refcounted *ref, gc_root_buff
13311332
gc_remove_from_roots(root);
13321333
GC_REF_SET_INFO(ref, 0);
13331334
root = NULL;
1335+
count++;
13341336
} else if (GC_REF_ADDRESS(ref) != 0
13351337
&& GC_REF_CHECK_COLOR(ref, GC_BLACK)) {
13361338
GC_TRACE_REF(ref, "removing from buffer");
13371339
GC_REMOVE_FROM_BUFFER(ref);
1340+
count++;
13381341
} else if (GC_TYPE(ref) == IS_REFERENCE) {
13391342
if (Z_REFCOUNTED(((zend_reference*)ref)->val)) {
13401343
ref = Z_COUNTED(((zend_reference*)ref)->val);
13411344
goto tail_call;
13421345
}
1343-
return;
1346+
return count;
13441347
} else {
1345-
return;
1348+
return count;
13461349
}
13471350

13481351
if (GC_TYPE(ref) == IS_OBJECT) {
@@ -1357,15 +1360,15 @@ static void gc_remove_nested_data_from_buffer(zend_refcounted *ref, gc_root_buff
13571360
ht = obj->handlers->get_gc(&tmp, &zv, &n);
13581361
end = zv + n;
13591362
if (EXPECTED(!ht)) {
1360-
if (!n) return;
1363+
if (!n) return count;
13611364
while (!Z_REFCOUNTED_P(--end)) {
1362-
if (zv == end) return;
1365+
if (zv == end) return count;
13631366
}
13641367
}
13651368
while (zv != end) {
13661369
if (Z_REFCOUNTED_P(zv)) {
13671370
ref = Z_COUNTED_P(zv);
1368-
gc_remove_nested_data_from_buffer(ref, NULL);
1371+
count += gc_remove_nested_data_from_buffer(ref, NULL);
13691372
}
13701373
zv++;
13711374
}
@@ -1374,15 +1377,15 @@ static void gc_remove_nested_data_from_buffer(zend_refcounted *ref, gc_root_buff
13741377
goto tail_call;
13751378
}
13761379
} else {
1377-
return;
1380+
return count;
13781381
}
13791382
} else if (GC_TYPE(ref) == IS_ARRAY) {
13801383
ht = (zend_array*)ref;
13811384
} else {
1382-
return;
1385+
return count;
13831386
}
13841387

1385-
if (!ht->nNumUsed) return;
1388+
if (!ht->nNumUsed) return count;
13861389
p = ht->arData;
13871390
end = p + ht->nNumUsed;
13881391
while (1) {
@@ -1394,7 +1397,7 @@ static void gc_remove_nested_data_from_buffer(zend_refcounted *ref, gc_root_buff
13941397
if (Z_REFCOUNTED_P(zv)) {
13951398
break;
13961399
}
1397-
if (p == end) return;
1400+
if (p == end) return count;
13981401
}
13991402
while (p != end) {
14001403
zv = &p->val;
@@ -1403,7 +1406,7 @@ static void gc_remove_nested_data_from_buffer(zend_refcounted *ref, gc_root_buff
14031406
}
14041407
if (Z_REFCOUNTED_P(zv)) {
14051408
ref = Z_COUNTED_P(zv);
1406-
gc_remove_nested_data_from_buffer(ref, NULL);
1409+
count += gc_remove_nested_data_from_buffer(ref, NULL);
14071410
}
14081411
p++;
14091412
}
@@ -1510,7 +1513,7 @@ ZEND_API int zend_gc_collect_cycles(void)
15101513
if (GC_IS_GARBAGE(current->ref)) {
15111514
p = GC_GET_PTR(current->ref);
15121515
if (GC_REFCOUNT(p) > refcounts[idx]) {
1513-
gc_remove_nested_data_from_buffer(p, current);
1516+
count -= gc_remove_nested_data_from_buffer(p, current);
15141517
}
15151518
}
15161519
current++;

0 commit comments

Comments
 (0)