Repository navigation
LeakSanitizer reports leaked code object during SQLAlchemy editable build on 3.15 and main #158963
Description
Activity
- addedtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
on Oct 7, 2026 Honestly I think it's too hard to investigate this from scratch. Can you first trim down the analysis and see if you can at least bisect the bad commit?
- addedpendingThe issue will be closed if no feedback is providedThe issue will be closed if no feedback is provided
on Oct 7, 2026 What does running with
-X showrefcountoutput? I've seen very similar leak traces in the past (with valgrind), but I can't remember if they were just false positives.If it is a real leak (meaning
-X showrefcountdisplays something other than[0 refs, 0 blocks]), we'll also need a pure-CPython repro; SQLAlchemy (or one of its dependencies) might simply have a memory leak.Here is a trimmed-down reproducer without SQLAlchemy, setuptools, or C compilation. It only requires
pip install Cython:# bug.py import tempfile from pathlib import Path from Cython.Compiler.Main import CompilationOptions, compile_single with tempfile.TemporaryDirectory() as d: src = Path(d) / "mre.py" src.write_text("from cython.cimports.cpython import PyTuple_New\n") compile_single( str(src), CompilationOptions(output_file=f"{d}/mre.c", language_level="3"), "mre", )
Running
./python -X showrefcount bug.pyoutputs:[92387 refs, 0 blocks] ==ERROR: LeakSanitizer: detected memory leaks Direct leak of 264 byte(s) in 1 object(s) allocated from: #0 malloc #1 _PyMem_DebugRawAlloc Objects/obmalloc.c:3103:24 #2 _PyObject_NewVar Objects/object.c:570:26 #3 _PyCode_New Objects/codeobject.c:734:10 #4 r_object Python/marshal.c:1734:29 ... SUMMARY: AddressSanitizer: 703 byte(s) leaked in 6 allocation(s).Note: Cython here is running as pure Python bytecode on 3.16 (no compiled .so C extensions of Cython are loaded), so the leaked PyCodeObject is retained inside CPython's own runtime/import path.
Do you have a repro without any third party packages?
@ZeroIntensity I was able to find one for 3.14, but unfortunately not yet for main or 3.15—though I'm still looking!
- addedinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)and removedpendingThe issue will be closed if no feedback is providedThe issue will be closed if no feedback is provided
on Oct 10, 2026 Please update the issue title as well and the description properly, at least for 3.14
Is this issue still relevant then?
- addedpendingThe issue will be closed if no feedback is providedThe issue will be closed if no feedback is provided
on Oct 10, 2026 Yes, this issue is still relevant. #158963 is about the LeakSanitizer report on 3.15 and main (3.16). The 3.14 JIT segfault, with its standard-library-only reproducer, is a different bug tracked in #158961. For #158963, my reduced reproducer still requires Cython; I have not found one without third-party packages yet. Please remove the
3.14label from this issue—it does not apply to #158963.
Bug report
I built both CPython checkouts with:
CC=clang CXX=clang++ LDFLAGS='-fuse-ld=lld' ./configure --with-tail-call-interp --enable-experimental-jit=yes --with-pydebug --with-address-sanitizer --with-undefined-behavior-sanitizer./python -VV:Python 3.15.0rc3+dev (heads/3.15:874d1122deb, Oct 7 2026, 14:48:22) [Clang 23.1.1 ]Python 3.16.0a0 (heads/main:37cc8dd0b9a, Oct 7 2026, 14:51:35) [Clang 23.1.1 ]From a SQLAlchemy checkout, I ran:
On 3.15,
setuptools.build_meta.prepare_metadata_for_build_editablecreated the metadata, then LeakSanitizer reported 852 bytes leaked in 6 allocations. On main,setuptools.build_meta.build_editablecreated the wheel, then LeakSanitizer reported 703 bytes leaked in 6 allocations. Both builds exited with status 1, souv syncfailed.Relevant excerpt from the main run (not the full log):
Expected: the build process exits without a LeakSanitizer error.
CPython versions tested on:
3.15, 3.16, CPython main branch
Operating systems tested on:
Linux