python / python/cpython

memory leak in threading stack size

Ouverte
#141,044 3 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

3.14 3.15 interpreter-core stdlib type-bug
Langage dominant
Python
Étoiles
77.2k
Forks
35.9k
Métriques de merge des PR
Métriques de PR en attente

Description

Bug report

Bug description:
import threading
previous = threading.stack_size(127 * 1024)
def worker():
    pass
t = threading.Thread(target=worker, name="worker-thread")
t.start()
threading.stack_size(0)
LeakSanitizer output on main
=================================================================
==3532388==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 88 byte(s) in 1 object(s) allocated from:
    #0 0x7e646db509c7 in malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:69
    #1 0x55cc45289c38 in _PyMem_RawMalloc ../Objects/obmalloc.c:63
    #2 0x55cc45289009 in _PyMem_DebugRawAlloc ../Objects/obmalloc.c:2887
    #3 0x55cc45289071 in _PyMem_DebugRawMalloc ../Objects/obmalloc.c:2920
    #4 0x55cc4528a8ef in _PyMem_DebugMalloc ../Objects/obmalloc.c:3085
    #5 0x55cc452b38dc in PyObject_Malloc ../Objects/obmalloc.c:1493
    #6 0x55cc454f3dd8 in _PyObject_MallocWithType ../Include/internal/pycore_object_alloc.h:46
    #7 0x55cc454f3dd8 in gc_alloc ../Python/gc.c:2344
    #8 0x55cc454f3f2e in _PyObject_GC_New ../Python/gc.c:2364
    #9 0x55cc451c9034 in PyMethod_New ../Objects/classobject.c:119
    #10 0x55cc452191a2 in cm_descr_get ../Objects/funcobject.c:1473
    #11 0x55cc452fdc1c in _Py_type_getattro_impl ../Objects/typeobject.c:6382
    #12 0x55cc452fde00 in _Py_type_getattro ../Objects/typeobject.c:6424
    #13 0x55cc45282b80 in PyObject_GetAttr ../Objects/object.c:1313
    #14 0x55cc45283dd3 in _PyObject_GetMethodStackRef ../Objects/object.c:1706
    #15 0x55cc45467d64 in _PyEval_EvalFrameDefault ../Python/generated_cases.c.h:7844
    #16 0x55cc45486105 in _PyEval_EvalFrame ../Include/internal/pycore_ceval.h:121
    #17 0x55cc454863f9 in _PyEval_Vector ../Python/ceval.c:2005
    #18 0x55cc451c12b7 in _PyFunction_Vectorcall ../Objects/call.c:413
    #19 0x55cc451c177e in _PyObject_VectorcallTstate ../Include/internal/pycore_call.h:169
    #20 0x55cc451c1c3c in _PyObject_CallFunctionVa ../Objects/call.c:552
    #21 0x55cc451c226d in callmethod ../Objects/call.c:626
    #22 0x55cc451c2472 in PyObject_CallMethod ../Objects/call.c:645
    #23 0x55cc45519b64 in init_importlib ../Python/import.c:3223
    #24 0x55cc4551ad12 in _PyImport_InitCore ../Python/import.c:4035
    #25 0x55cc45563be1 in pycore_interp_init ../Python/pylifecycle.c:942
    #26 0x55cc45563e06 in pyinit_config ../Python/pylifecycle.c:971
    #27 0x55cc455712e3 in pyinit_core ../Python/pylifecycle.c:1134
    #28 0x55cc4557153b in Py_InitializeFromConfig ../Python/pylifecycle.c:1454
    #29 0x55cc455d4c9e in pymain_init ../Modules/main.c:68
    #30 0x55cc455d50dc in pymain_main ../Modules/main.c:793

Indirect leak of 96 byte(s) in 1 object(s) allocated from:
    #0 0x7e646db509c7 in malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:69
    #1 0x55cc45289c38 in _PyMem_RawMalloc ../Objects/obmalloc.c:63
    #2 0x55cc45289009 in _PyMem_DebugRawAlloc ../Objects/obmalloc.c:2887
    #3 0x55cc45289071 in _PyMem_DebugRawMalloc ../Objects/obmalloc.c:2920
    #4 0x55cc4528a8ef in _PyMem_DebugMalloc ../Objects/obmalloc.c:3085
    #5 0x55cc452b38dc in PyObject_Malloc ../Objects/obmalloc.c:1493
    #6 0x55cc454f3dd8 in _PyObject_MallocWithType ../Include/internal/pycore_object_alloc.h:46
    #7 0x55cc454f3dd8 in gc_alloc ../Python/gc.c:2344
    #8 0x55cc454f4037 in _PyObject_GC_NewVar ../Python/gc.c:2386
    #9 0x55cc452c9d82 in tuple_alloc ../Objects/tupleobject.c:57
    #10 0x55cc452cca50 in PyTuple_New ../Objects/tupleobject.c:81
    #11 0x55cc4554f81d in r_object ../Python/marshal.c:1372
    #12 0x55cc455504e9 in r_object ../Python/marshal.c:1560
    #13 0x55cc4554f9d8 in r_object ../Python/marshal.c:1378
    #14 0x55cc455504b9 in r_object ../Python/marshal.c:1554
    #15 0x55cc45551305 in read_object ../Python/marshal.c:1714
    #16 0x55cc45551558 in marshal_loads_impl ../Python/marshal.c:2059
    #17 0x55cc45551c95 in marshal_loads ../Python/clinic/marshal.c.h:344
    #18 0x55cc45446cfa in _PyEval_EvalFrameDefault ../Python/generated_cases.c.h:2361
    #19 0x55cc45486105 in _PyEval_EvalFrame ../Include/internal/pycore_ceval.h:121
    #20 0x55cc454863f9 in _PyEval_Vector ../Python/ceval.c:2005
    #21 0x55cc451c12b7 in _PyFunction_Vectorcall ../Objects/call.c:413
    #22 0x55cc451c177e in _PyObject_VectorcallTstate ../Include/internal/pycore_call.h:169
    #23 0x55cc451c34bf in object_vacall ../Objects/call.c:819
    #24 0x55cc451c373d in PyObject_CallMethodObjArgs ../Objects/call.c:886
    #25 0x55cc455133c5 in import_find_and_load ../Python/import.c:3688
    #26 0x55cc4551a2f5 in PyImport_ImportModuleLevelObject ../Python/import.c:3770
    #27 0x55cc454357c3 in _PyEval_ImportName ../Python/ceval.c:3025
    #28 0x55cc4545e461 in _PyEval_EvalFrameDefault ../Python/generated_cases.c.h:6219
    #29 0x55cc45486105 in _PyEval_EvalFrame ../Include/internal/pycore_ceval.h:121
    #30 0x55cc454863f9 in _PyEval_Vector ../Python/ceval.c:2005

Indirect leak of 96 byte(s) in 1 object(s) allocated from:
    #0 0x7e646db509c7 in malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:69
    #1 0x55cc45289c38 in _PyMem_RawMalloc ../Objects/obmalloc.c:63
    #2 0x55cc45289009 in _PyMem_DebugRawAlloc ../Objects/obmalloc.c:2887
    #3 0x55cc45289071 in _PyMem_DebugRawMalloc ../Objects/obmalloc.c:2920
    #4 0x55cc4528a8ef in _PyMem_DebugMalloc ../Objects/obmalloc.c:3085
    #5 0x55cc452b38dc in PyObject_Malloc ../Objects/obmalloc.c:1493
    #6 0x55cc454f3dd8 in _PyObject_MallocWithType ../Include/internal/pycore_object_alloc.h:46
    #7 0x55cc454f3dd8 in gc_alloc ../Python/gc.c:2344
    #8 0x55cc454f3f2e in _PyObject_GC_New ../Python/gc.c:2364
    #9 0x55cc45276170 in PyCMethod_New ../Objects/methodobject.c:108
    #10 0x55cc451dea0b in method_get ../Objects/descrobject.c:158
    #11 0x55cc45284b2c in _PyObject_GenericGetAttrWithDict ../Objects/object.c:1893
    #12 0x55cc45285b28 in PyObject_GenericGetAttr ../Objects/object.c:1923
    #13 0x55cc45282b80 in PyObject_GetAttr ../Objects/object.c:1313
    #14 0x55cc45467f8a in _PyEval_EvalFrameDefault ../Python/generated_cases.c.h:7865
    #15 0x55cc45486105 in _PyEval_EvalFrame ../Include/internal/pycore_ceval.h:121
    #16 0x55cc454863f9 in _PyEval_Vector ../Python/ceval.c:2005
    #17 0x55cc451c12b7 in _PyFunction_Vectorcall ../Objects/call.c:413
    #18 0x55cc451c78c7 in _PyObject_VectorcallTstate ../Include/internal/pycore_call.h:169
    #19 0x55cc451c7d81 in method_vectorcall ../Objects/classobject.c:73
    #20 0x55cc451c4ad1 in _PyVectorcall_Call ../Objects/call.c:273
    #21 0x55cc451c50dd in _PyObject_Call ../Objects/call.c:348
    #22 0x55cc451c5123 in PyObject_Call ../Objects/call.c:373
    #23 0x55cc456d25b9 in thread_run ../Modules/_threadmodule.c:387
    #24 0x55cc455ade23 in pythread_wrapper ../Python/thread_pthread.h:234
    #25 0x7e646dab1a41 in asan_thread_start ../../../../src/libsanitizer/asan/asan_interceptors.cpp:234
    #26 0x7e646d7f4aa3  (/lib/x86_64-linux-gnu/libc.so.6+0x9caa3) (BuildId: 282c2c16e7b6600b0b22ea0c99010d2795752b5f)

Indirect leak of 88 byte(s) in 1 object(s) allocated from:
    #0 0x7e646db509c7 in malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:69
    #1 0x55cc45289c38 in _PyMem_RawMalloc ../Objects/obmalloc.c:63
    #2 0x55cc45289009 in _PyMem_DebugRawAlloc ../Objects/obmalloc.c:2887
    #3 0x55cc45289071 in _PyMem_DebugRawMalloc ../Objects/obmalloc.c:2920
    #4 0x55cc4528a8ef in _PyMem_DebugMalloc ../Objects/obmalloc.c:3085
    #5 0x55cc452b38dc in PyObject_Malloc ../Objects/obmalloc.c:1493
    #6 0x55cc454f3dd8 in _PyObject_MallocWithType ../Include/internal/pycore_object_alloc.h:46
    #7 0x55cc454f3dd8 in gc_alloc ../Python/gc.c:2344
    #8 0x55cc454f3f2e in _PyObject_GC_New ../Python/gc.c:2364
    #9 0x55cc45250446 in new_dict ../Objects/dictobject.c:875
    #10 0x55cc45251b2f in PyDict_New ../Objects/dictobject.c:973
    #11 0x55cc45251b7e in dict_new_presized ../Objects/dictobject.c:2204
    #12 0x55cc45259e23 in _PyDict_FromItems ../Objects/dictobject.c:2245
    #13 0x55cc45440114 in _PyEval_EvalFrameDefault ../Python/generated_cases.c.h:1272
    #14 0x55cc45486105 in _PyEval_EvalFrame ../Include/internal/pycore_ceval.h:121
    #15 0x55cc454863f9 in _PyEval_Vector ../Python/ceval.c:2005
    #16 0x55cc451c12b7 in _PyFunction_Vectorcall ../Objects/call.c:413
    #17 0x55cc451c177e in _PyObject_VectorcallTstate ../Include/internal/pycore_call.h:169
    #18 0x55cc451c34bf in object_vacall ../Objects/call.c:819
    #19 0x55cc451c373d in PyObject_CallMethodObjArgs ../Objects/call.c:886
    #20 0x55cc455133c5 in import_find_and_load ../Python/import.c:3688
    #21 0x55cc4551a2f5 in PyImport_ImportModuleLevelObject ../Python/import.c:3770
    #22 0x55cc45426967 in builtin___import___impl ../Python/bltinmodule.c:285
    #23 0x55cc45426c32 in builtin___import__ ../Python/clinic/bltinmodule.c.h:110
    #24 0x55cc4527491b in cfunction_vectorcall_FASTCALL_KEYWORDS ../Objects/methodobject.c:465
    #25 0x55cc451c177e in _PyObject_VectorcallTstate ../Include/internal/pycore_call.h:169
    #26 0x55cc451c1c3c in _PyObject_CallFunctionVa ../Objects/call.c:552
    #27 0x55cc451c1e61 in PyObject_CallFunction ../Objects/call.c:574
    #28 0x55cc4551a8f4 in PyImport_Import ../Python/import.c:3962
    #29 0x55cc4551aa9f in PyImport_ImportModule ../Python/import.c:3410
    #30 0x55cc45564580 in init_import_site ../Python/pylifecycle.c:2741

Indirect leak of 88 byte(s) in 1 object(s) allocated from:
    #0 0x7e646db509c7 in malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:69
    #1 0x55cc45289c38 in _PyMem_RawMalloc ../Objects/obmalloc.c:63
    #2 0x55cc45289009 in _PyMem_DebugRawAlloc ../Objects/obmalloc.c:2887
    #3 0x55cc45289071 in _PyMem_DebugRawMalloc ../Objects/obmalloc.c:2920
    #4 0x55cc4528a8ef in _PyMem_DebugMalloc ../Objects/obmalloc.c:3085
    #5 0x55cc452b38dc in PyObject_Malloc ../Objects/obmalloc.c:1493
    #6 0x55cc454f3dd8 in _PyObject_MallocWithType ../Include/internal/pycore_object_alloc.h:46
    #7 0x55cc454f3dd8 in gc_alloc ../Python/gc.c:2344
    #8 0x55cc454f3f2e in _PyObject_GC_New ../Python/gc.c:2364
    #9 0x55cc45250446 in new_dict ../Objects/dictobject.c:875
    #10 0x55cc45251b2f in PyDict_New ../Objects/dictobject.c:973
    #11 0x55cc4542fff5 in initialize_locals ../Python/ceval.c:1583
    #12 0x55cc45432fd4 in _PyEvalFramePushAndInit ../Python/ceval.c:1875
    #13 0x55cc454863cf in _PyEval_Vector ../Python/ceval.c:1995
    #14 0x55cc451c12b7 in _PyFunction_Vectorcall ../Objects/call.c:413
    #15 0x55cc451c4453 in _PyObject_VectorcallDictTstate ../Objects/call.c:135
    #16 0x55cc451c4878 in _PyObject_Call_Prepend ../Objects/call.c:504
    #17 0x55cc452dae55 in slot_tp_new ../Objects/typeobject.c:10874
    #18 0x55cc452e93f8 in type_call ../Objects/typeobject.c:2449
    #19 0x55cc451c1570 in _PyObject_MakeTpCall ../Objects/call.c:242
    #20 0x55cc451c4589 in _PyObject_VectorcallDictTstate ../Objects/call.c:130
    #21 0x55cc451c46ac in PyObject_VectorcallDict ../Objects/call.c:159
    #22 0x55cc45427cda in builtin___build_class__ ../Python/bltinmodule.c:213
    #23 0x55cc4527491b in cfunction_vectorcall_FASTCALL_KEYWORDS ../Objects/methodobject.c:465
    #24 0x55cc451c177e in _PyObject_VectorcallTstate ../Include/internal/pycore_call.h:169
    #25 0x55cc451c1871 in PyObject_Vectorcall ../Objects/call.c:327
    #26 0x55cc45449f11 in _PyEval_EvalFrameDefault ../Python/generated_cases.c.h:2920
    #27 0x55cc45486105 in _PyEval_EvalFrame ../Include/internal/pycore_ceval.h:121
    #28 0x55cc454863f9 in _PyEval_Vector ../Python/ceval.c:2005
    #29 0x55cc454866a9 in PyEval_EvalCode ../Python/ceval.c:888
    #30 0x55cc45424bcb in builtin_exec_impl ../Python/bltinmodule.c:1180

Indirect leak of 88 byte(s) in 1 object(s) allocated from:
    #0 0x7e646db509c7 in malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:69
    #1 0x55cc45289c38 in _PyMem_RawMalloc ../Objects/obmalloc.c:63
    #2 0x55cc45289009 in _PyMem_DebugRawAlloc ../Objects/obmalloc.c:2887
    #3 0x55cc45289071 in _PyMem_DebugRawMalloc ../Objects/obmalloc.c:2920
    #4 0x55cc4528a8ef in _PyMem_DebugMalloc ../Objects/obmalloc.c:3085
    #5 0x55cc452b38dc in PyObject_Malloc ../Objects/obmalloc.c:1493
    #6 0x55cc454f3dd8 in _PyObject_MallocWithType ../Include/internal/pycore_object_alloc.h:46
    #7 0x55cc454f3dd8 in gc_alloc ../Python/gc.c:2344
    #8 0x55cc454f3f2e in _PyObject_GC_New ../Python/gc.c:2364
    #9 0x55cc451c9034 in PyMethod_New ../Objects/classobject.c:119
    #10 0x55cc452191a2 in cm_descr_get ../Objects/funcobject.c:1473
    #11 0x55cc452fdc1c in _Py_type_getattro_impl ../Objects/typeobject.c:6382
    #12 0x55cc452fde00 in _Py_type_getattro ../Objects/typeobject.c:6424
    #13 0x55cc45282b80 in PyObject_GetAttr ../Objects/object.c:1313
    #14 0x55cc45467f8a in _PyEval_EvalFrameDefault ../Python/generated_cases.c.h:7865
    #15 0x55cc45486105 in _PyEval_EvalFrame ../Include/internal/pycore_ceval.h:121
    #16 0x55cc454863f9 in _PyEval_Vector ../Python/ceval.c:2005
    #17 0x55cc451c12b7 in _PyFunction_Vectorcall ../Objects/call.c:413
    #18 0x55cc451c177e in _PyObject_VectorcallTstate ../Include/internal/pycore_call.h:169
    #19 0x55cc451c34bf in object_vacall ../Objects/call.c:819
    #20 0x55cc451c373d in PyObject_CallMethodObjArgs ../Objects/call.c:886
    #21 0x55cc455133c5 in import_find_and_load ../Python/import.c:3688
    #22 0x55cc4551a2f5 in PyImport_ImportModuleLevelObject ../Python/import.c:3770
    #23 0x55cc454357c3 in _PyEval_ImportName ../Python/ceval.c:3025
    #24 0x55cc4545e461 in _PyEval_EvalFrameDefault ../Python/generated_cases.c.h:6219
    #25 0x55cc45486105 in _PyEval_EvalFrame ../Include/internal/pycore_ceval.h:121
    #26 0x55cc454863f9 in _PyEval_Vector ../Python/ceval.c:2005
    #27 0x55cc451c12b7 in _PyFunction_Vectorcall ../Objects/call.c:413
    #28 0x55cc451c177e in _PyObject_VectorcallTstate ../Include/internal/pycore_call.h:169
    #29 0x55cc451c1ae5 in _PyObject_CallNoArgsTstate ../Include/internal/pycore_call.h:176
    #30 0x55cc451c1ae5 in _PyObject_CallFunctionVa ../Objects/call.c:531
    #31 0x55cc451c226d in callmethod ../Objects/call.c:626

SUMMARY: AddressSanitizer: 544 byte(s) leaked in 6 allocation(s).
CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

Linked PRs
  • gh-157691

Guide de contribution

Ouvrir le guide de contribution

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Piste de recherche

Commencez par reproduire l’exemple avec LeakSanitizer, puis inspectez le chemin thread_run dans Modules/_threadmodule.c et pythread_wrapper dans Python/thread_pthread.h. Suivez les allocations associées à threading.stack_size() et confirmez si la fuite signalée y est gérée ou libérée. C’est terminé lorsque le reproducteur ne signale plus la fuite.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
c, python
Domaine
operating-systems
Type d'issue
Bug
Difficulté
4/5
Temps estimé
3-5 jours
Activité
Active
Clarté
Plutôt claire
Accessibilité débutants
48/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.