php / php/php-src

Clarification on refcounting behavior of object handlers/get_gc

Aperta
#19,230 4 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Bug Category: GC Status: Needs Triage
Lingua principale
C
Stelle
40.4k
Fork
8.1k
Merge medio
2g 13h
PR unite (30g)
96

Descrizione

Description

When implementing https://github.com/mongodb/mongo-php-driver/pull/1850, I have encountered some strange refcounting behavior within the garbage collector; specifically, when working with the hashtable returned by get_gc in https://github.com/php/php-src/blob/master/Zend/zend_gc.c#L892 and https://github.com/php/php-src/blob/master/Zend/zend_gc.c#L1516 the refcount is incremented and then seemingly not decremented again (leading to the leaks I'm fighting in https://github.com/mongodb/mongo-php-driver/pull/1850), but in https://github.com/php/php-src/blob/master/Zend/zend_gc.c#L1068, the refcount is decremented correctly.

This brings the question: what should be the refcount of the hashtables returned by get_gc, get_properties_for (in all of the various modes), get_properties, get_debug_info, and all other object handlers?

This detail is not documented anywhere, and specifically for get_gc, it's especially not clear given that returning a refcount of 0 would cause a negative refcount in one place, and returning 1 causes a leak in other two places (though that may be due to an issue in my implementation in the https://github.com/mongodb/mongo-php-driver/pull/1850 PR, though it's not immediately obvious what it is to me).

It would be super nice to have it documented at least inside of the source code as comments too...

PHP Version
8.4.10
Operating System

No response

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia con le sezioni referenziate di Zend/zend_gc.c intorno alle righe 892, 1068 e 1516, quindi confronta il comportamento di get_gc con get_properties_for, get_properties e get_debug_info. Esamina la pull request collegata di mongo-php-driver per le perdite segnalate; il lavoro è completato quando la responsabilità prevista del refcount per ogni handler è stabilita e documentata nei commenti pertinenti del codice sorgente.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
c, php
Ambito
documentation
Tipo di issue
Documentazione
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Da chiarire
Idoneità per principianti
30/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.