Method call may leak if releasing EG(This) triggers GC
Nessuno ha ancora preso questa issue.
- Lingua principale
- C
- Stelle
- 40.4k
- Fork
- 8.2k
- Merge medio
- 2g 13h
- PR unite (30g)
- 96
Descrizione
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
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Riprodurre il leak con l’esempio test.php, quindi esaminare i siti di chiamata collegati di zend_vm_def.h intorno alle righe 2866 e 4019 e il report del leak proveniente da Zend/zend_objects.c. Confermare che la correzione impedisca all’oggetto ciclico restituito di rimanere non raccolto e che l’esempio non segnali più un memory leak.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- c, php
- Ambito
- backend
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 38/100