Method call may leak if releasing EG(This) triggers GC
还没有人认领这个 Issue。
评估
调研方向
使用 test.php 示例重现内存泄漏,然后检查 zend_vm_def.h 中 2866 行和 4019 行附近链接的调用点,以及来自 Zend/zend_objects.c 的泄漏报告。确认修复不会让返回的循环对象继续处于未回收状态,并确认该示例不再报告内存泄漏。
由索引模型根据 Issue 内容生成。
描述
Description
Method calls may cause their return value to leak if releasing EG(This) triggers GC.
The following code:
<?php
class A {
public $cycle;
public function __construct() { $this->cycle = $this; }
}
class B {
public function get() {
return new A();
}
}
$c = new B();
$objs = [];
while (gc_status()['roots']+2 < gc_status()['threshold']) {
$obj = new stdClass;
$objs[] = $obj;
}
var_dump($c->get());
Resulted in a memory leak:
Script: 'test.php'
Zend/zend_objects.c(189) : Freeing 0x00007ffff7a5c840 (56 bytes), script=test.php
=== Total 1 memory leaks detected ===
Here is what is happening:
- After returning from
get(),$cis released, which triggers GCAis removed from buffer, and is not collected because it's referenced by the call stack
- After returning from
var_dump(),zend_vm_stack_free_args()releasesAwithzval_ptr_dtor_nogc(), soAis not added to the GC buffer - At this point nothing references
Abut itself, andAis not in the GC buffer, so it leaks
I'm not sure how to fix this appart from switching to zval_ptr_dtor().
PHP Version
master
Operating System
No response
- 主要语言
- C
- 星标
- 40.4k
- 派生
- 8.2k
- 平均合并
- 2 天 15 小时
- 30 天内合并 PR
- 103
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
php/php-src 的其他 Issue
-
Bug SAPI: cli_server Status: Verified
难度 2/5 1-3 小时 新手友好度 88/100
-
Bug Status: Needs Triage
难度 2/5 1-3 小时 新手友好度 76/100
-
Bug Status: Needs Triage
难度 1/5 1 小时以内 新手友好度 90/100
-
Bug Status: Needs Triage
难度 2/5 1-3 小时 新手友好度 78/100
-
Bug Category: Tests Status: Verified
难度 2/5 1-3 小时 新手友好度 68/100
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 88/100
zephyrproject-rtos/zephyr#119726 ·
-
[Bounty proposal] fix(web): memory insights count an evening memory on the next day ($25 proposed) 未关闭
难度 2/5 1-3 小时 新手友好度 84/100
BasedHardware/omi#15320 ·
-
[adam] AdamNet network read doesn't cap to MAX_ADAM_PACKET_LEN, overflows client receive buffers 未关闭
难度 2/5 1-3 小时 新手友好度 88/100
FujiNetWIFI/fujinet-firmware#1649 · 2 条评论 ·
-
难度 2/5 1-3 小时 新手友好度 68/100
HarbourMasters/Shipwright#7229 ·
-
难度 2/5 1-3 小时 新手友好度 72/100
riscv-software-src/riscv-isa-sim#2435 · 1 条评论 ·