Method call may leak if releasing EG(This) triggers GC
まだ誰も着手していません。
評価
調査の方向性
test.php の例でリークを再現し、続いて 2866 行目と 4019 行目付近にある、リンクされた zend_vm_def.h の呼び出し箇所と、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時間
- マージ済み PR(30日)
- 103
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- 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
-
[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 件 ·
-
bug Self Built Image SNAPSHOT Supported Device target/ramips
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100