php / php/php-src

Clarification on refcounting behavior of object handlers/get_gc

Abierto
#19,230 4 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Bug Category: GC Status: Needs Triage
Lenguaje dominante
C
Estrellas
40.4k
Forks
8.1k
Merge medio
2 d 13 h
PR fusionados (30 d)
96

Descripción

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

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

Comienza con las secciones referenciadas de Zend/zend_gc.c alrededor de las líneas 892, 1068 y 1516; después compara el comportamiento de get_gc con get_properties_for, get_properties y get_debug_info. Revisa el pull request enlazado de mongo-php-driver para comprobar las fugas reportadas; se considera terminado cuando la responsabilidad esperada sobre el refcount de cada handler esté establecida y documentada en los comentarios relevantes del código fuente.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
c, php
Área
documentation
Tipo de issue
Documentación
Dificultad
4/5
Tiempo estimado
3-5 días
Estado de actividad
Estancado
Claridad
Necesita aclaración
Aptitud para principiantes
30/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.