GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — LeakSanitizer detects memory leaks in test_import with _testsinglephase module in subinterpreter · Issue #140404 · python/cpython

LeakSanitizer detects memory leaks in test_import with _testsinglephase module in subinterpreter #140404

New issue
Copy link
New issue
Copy link
Open
Open
LeakSanitizer detects memory leaks in test_import with _testsinglephase module in subinterpreter#140404
Copy link
Labels
pendingThe issue will be closed if no feedback is providedThe issue will be closed if no feedback is providedtestsTests in the Lib/test dirTests in the Lib/test dirtopic-subinterpreterstype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Description

@ashm-dev
ashm-dev
opened on Oct 21, 2025
Issue body actions

Bug report

Bug description:

LeakSanitizer detects memory leaks when running test_import with the _testsinglephase module loaded in a subinterpreter.

How to Reproduce

Build:

CC=clang CXX=clang++ ./configure --disable-optimizations --with-pydebug --with-address-sanitizer && make -j$(nproc)

Run:

./python -X dev -X showrefcount -m test test_import -j0

Leak Summary

==643791==ERROR: LeakSanitizer: detected memory leaks
SUMMARY: AddressSanitizer: 6709 byte(s) leaked in 45 allocation(s).

Code Locations

The leaks originate from:

Subinterpreter execution:

  • cpython/Modules/_testcapimodule.c

    Line 1223 in e8e0f41

    r = PyRun_SimpleStringFlags(code, &cflags);

    (run_in_subinterp)

Module initialization:

  • cpython/Modules/_testsinglephase.c

    Line 516 in e8e0f41

    if (init_state(state) < 0) {

    (init__testsinglephase_basic)
  • cpython/Modules/_testsinglephase.c

    Line 303 in e8e0f41

    state->error = PyErr_NewException("_testsinglephase.error", NULL, NULL);

    (init_state with PyErr_NewException)

Import machinery:

  • cpython/Python/importdl.c

    Line 429 in e8e0f41

    PyObject *m = p0();

    (_PyImport_RunModInitFunc)

Leaked Objects

  • Type objects (1016 bytes × 2): via type_new → PyErr_NewException
  • Dictionary keys (424 bytes × 2): via new_keys_object → PyDict_SetItemString
  • PyCMethod objects (384 bytes × 2 groups): via PyModule_AddFunctions
  • Additional: Unicode strings, tuples, dictionaries

Full Output

See attached .log files for complete LeakSanitizer output for each version.

312.log
313.log
314.log
main.log

CPython versions tested on:

3.12, 3.13, 3.14, 3.15, CPython main branch

Operating systems tested on:

Linux

Activity

  1. ashm-dev
    added
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    on Oct 21, 2025
  2. sergey-miryanov
    added
    testsTests in the Lib/test dirTests in the Lib/test dir
    topic-subinterpreters
    on Oct 21, 2025
  3. github-project-automation
    added this to Subinterpreterson Oct 21, 2025
  4. github-project-automation
    moved this to Todo in Subinterpreterson Oct 21, 2025
  5. ZeroIntensity commented on Oct 21, 2025

    @ZeroIntensity
    ZeroIntensity
    on Oct 21, 2025
    Member
    More actions

    I think this is fundamentally an unsolvable problem with single-phase initialization. Single-phase doesn't provide a way to clean up process-global state, so things leak. We added multi-phase to fix this problem.

  6. ZeroIntensity
    added
    pendingThe issue will be closed if no feedback is providedThe issue will be closed if no feedback is provided
    on Oct 21, 2025
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

    pendingThe issue will be closed if no feedback is providedThe issue will be closed if no feedback is providedtestsTests in the Lib/test dirTests in the Lib/test dirtopic-subinterpreterstype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

    Projects

    • Subinterpreters
      Status
      Todo
      Show more project fields

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402503 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.