Skip to content

Commit 8972938

Browse files
committed
Fix missing addref for Countable::count()
Fixes GH-21605
1 parent e50cd12 commit 8972938

File tree

4 files changed

+33
-0
lines changed

4 files changed

+33
-0
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ PHP NEWS
77
destructors). (iliaal)
88
. Fixed bug GH-21478 (Forward property operations to real instance for
99
initialized lazy proxies). (iliaal)
10+
. Fixed bug GH-21605 (Missing addref for Countable::count()). (ilutov)
1011

1112
- Curl:
1213
. Add support for brotli and zstd on Windows. (Shivam Mathur)

Zend/tests/gh21605.phpt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
--TEST--
2+
GH-21605: Missing addref for Countable::count()
3+
--CREDITS--
4+
cnwangjihe
5+
--FILE--
6+
<?php
7+
8+
class C implements Countable {
9+
public function count(): int {
10+
global $c;
11+
$c = null;
12+
var_dump($this);
13+
return 42;
14+
}
15+
}
16+
17+
$c = new C;
18+
var_dump(count($c));
19+
20+
?>
21+
--EXPECTF--
22+
object(C)#%d (0) {
23+
}
24+
int(42)

Zend/zend_vm_def.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9419,7 +9419,9 @@ ZEND_VM_COLD_CONST_HANDLER(190, ZEND_COUNT, CONST|TMPVAR|CV, UNUSED)
94199419
zval retval;
94209420

94219421
zend_function *count_fn = zend_hash_find_ptr(&zobj->ce->function_table, ZSTR_KNOWN(ZEND_STR_COUNT));
9422+
GC_ADDREF(zobj);
94229423
zend_call_known_instance_method_with_0_params(count_fn, zobj, &retval);
9424+
OBJ_RELEASE(zobj);
94239425
count = zval_get_long(&retval);
94249426
zval_ptr_dtor(&retval);
94259427
break;

Zend/zend_vm_execute.h

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)