Memory leak on interpreter shutdown when reference cycle exists between `structseq` type and its instance
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 25/100
Línea de trabajo
Empieza con el reproducer en el ASan/UBSan pydebug build y, después, inspecciona Objects/structseq.c y las rutas de asignación en Objects/typeobject.c, Python/gc.c y Modules/timemodule.c. Compara el comportamiento con el PR enlazado gh-157179. Se considera terminado cuando el ciclo ya no produce fugas de LeakSanitizer durante el apagado del intérprete.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Bug report
Bug description:
Environment
- Commit/Branch:
main(rev:2d9fb5f2f70b18ce9e5d9f7f76fd5ef3f118d838) - OS: Linux
- Build flags:
CC=clang CXX=clang++ LDFLAGS='-fuse-ld=lld' ./configure --with-address-sanitizer --with-undefined-behavior-sanitizer --with-pydebug && make -j$(nproc)
Steps to reproduce
Run:
./python -c "import time; t = time.gmtime(); type(t).refcyle = t;"
Note: Explicitly breaking the cycle avoids the leak:
./python -c "import time; t = time.gmtime(); type(t).refcyle = t; del type(t).refcyle"
Expected behavior
The garbage collector or interpreter finalization breaks the reference cycle during shutdown; no memory leaks reported by LeakSanitizer.
Actual behavior
LeakSanitizer detects memory leaks (indirect leaks of the type, its dict, descriptors, and the instance):
=================================================================
==1164172==ERROR: LeakSanitizer: detected memory leaks
Indirect leak of 1472 byte(s) in 1 object(s) allocated from:
#0 0x55571ba2f651 in malloc
#1 0x55571c0c8db7 in _PyMem_DebugRawAlloc Objects/obmalloc.c:3103:24
#2 0x55571c130728 in _PyObject_MallocWithType Include/internal/pycore_object_alloc.h:46:17
#3 0x55571c130728 in _PyType_AllocNoTrack Objects/typeobject.c:2495:19
#4 0x55571c13040d in PyType_GenericAlloc Objects/typeobject.c:2526:21
#5 0x55571c1357f9 in type_from_slots_or_spec Objects/typeobject.c:5591:30
#6 0x55571c1148ec in _PyStructSequence_NewType Objects/structseq.c:780:28
#7 0x55571ca6ea5c in time_exec Modules/timemodule.c:2113:31
...
Indirect leak of 176 byte(s) in 1 object(s) allocated from:
#0 0x55571ba2f651 in malloc
#1 0x55571c0c8db7 in _PyMem_DebugRawAlloc Objects/obmalloc.c:3103:24
#2 0x55571c5d4028 in _PyObject_MallocWithType Include/internal/pycore_object_alloc.h:46:17
#3 0x55571c5d4028 in gc_alloc Python/gc.c:2013:17
#4 0x55571c5d4440 in _PyObject_GC_NewVar Python/gc.c:2055:25
#5 0x55571c110247 in PyStructSequence_New Objects/structseq.c:77:11
#6 0x55571ca69e1d in tmtotuple Modules/timemodule.c:463:19
#7 0x55571ca67616 in time_gmtime Modules/timemodule.c:541:12
...
SUMMARY: AddressSanitizer: 6946 byte(s) leaked in 50 allocation(s).
Full LeakSanitizer output - logs.txt
CPython versions tested on:
CPython main branch
Operating systems tested on:
Linux
Linked PRs
- gh-157179
- Lenguaje dominante
- Python
- Estrellas
- 77.2k
- Forks
- 36k
- Merge medio
- 1 d 9 h
- PR fusionados (30 d)
- 558
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de python/cpython
-
docs pending
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
-
stdlib type-feature
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
-
stdlib type-feature
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
-
build type-bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
-
stdlib topic-email type-feature
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
Todos los issues de python/cpython
Issues similares
-
🐛 Bug 🔔 Pending processing
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
jumpserver/jumpserver#17584 ·
-
link-check link-check:sphinx-theme
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 90/100
modelscope/DiffSynth-Studio#1702 ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 65/100
qgis/QGIS-Documentation#11275 ·
-
bug priority:normal ready-for-dev
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
OpenHands/extensions#626 · 1 comentario ·