Skip to content

memory leak with glob and mock in JIT #139750

Description

@YuanchengJiang

Bug report

Bug description:

import glob
from unittest import mock
def fake_glob(pattern):
        return []
with mock.patch('glob.glob', side_effect=fake_glob):
    for _ in range(4096):
        r = glob.glob('*.txt')
import http.cookiejar

Config: --enable-experimental-jit=yes --with-address-sanitizer

ASan:

=================================================================
==1634280==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 1216 byte(s) in 1 object(s) allocated from:
    #0 0x702100c829c7 in malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:69
    #1 0x5de919b956b7 in _PyObject_MallocWithType ../Include/internal/pycore_object_alloc.h:46
    #2 0x5de919b956b7 in gc_alloc ../Python/gc.c:2327
    #3 0x5de919b956b7 in _PyObject_GC_NewVar ../Python/gc.c:2369
    #4 0x5de919c73e54 in make_executor_from_uops ../Python/optimizer.c:1120
    #5 0x5de919c73e54 in uop_optimize ../Python/optimizer.c:1341
    #6 0x5de919c73e54 in _PyOptimizer_Optimize ../Python/optimizer.c:136
    #7 0x5de91963d940 in _PyEval_EvalFrameDefault ../Python/generated_cases.c.h:7656
    #8 0x5de919aff686 in _PyEval_EvalFrame ../Include/internal/pycore_ceval.h:121
    #9 0x5de919aff686 in _PyEval_Vector ../Python/ceval.c:1997
    #10 0x5de919aff686 in PyEval_EvalCode ../Python/ceval.c:880
    #11 0x5de919cbcb0e in run_eval_code_obj ../Python/pythonrun.c:1365
    #12 0x5de919cbcb0e in run_mod ../Python/pythonrun.c:1459
    #13 0x5de919cc17b7 in pyrun_file ../Python/pythonrun.c:1293
    #14 0x5de919cc17b7 in _PyRun_SimpleFileObject ../Python/pythonrun.c:521
    #15 0x5de919cc22dc in _PyRun_AnyFileObject ../Python/pythonrun.c:81
    #16 0x5de919d3ebdc in pymain_run_file_obj ../Modules/main.c:410
    #17 0x5de919d3ebdc in pymain_run_file ../Modules/main.c:429
    #18 0x5de919d3ebdc in pymain_run_python ../Modules/main.c:691
    #19 0x5de919d404be in Py_RunMain ../Modules/main.c:772
    #20 0x5de919d404be in pymain_main ../Modules/main.c:802
    #21 0x5de919d404be in Py_BytesMain ../Modules/main.c:826
    #22 0x7021008b41c9  (/lib/x86_64-linux-gnu/libc.so.6+0x2a1c9) (BuildId: 282c2c16e7b6600b0b22ea0c99010d2795752b5f)
    #23 0x7021008b428a in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2a28a) (BuildId: 282c2c16e7b6600b0b22ea0c99010d2795752b5f)
    #24 0x5de919662f54 in _start (/home/fuzz/WorkSpace/flowfusion-cpython/cpython/build/python+0x218f54) (BuildId: 3087b1f6c97d85c049f8eaa36e3ac5b15eccf317)

SUMMARY: AddressSanitizer: 1216 byte(s) leaked in 1 allocation(s).

CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

Activity

  1. picnixz commented on Oct 8, 2025

    @picnixz
    Member

    This is the same issue as before. Executors are leaked.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions