Skip to content

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

@ashm-dev

Description

@ashm-dev

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:

Module initialization:

Import machinery:

Leaked Objects

  • Type objects (1016 bytes × 2): via type_newPyErr_NewException
  • Dictionary keys (424 bytes × 2): via new_keys_objectPyDict_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

Metadata

Metadata

Assignees

No one assigned

    Labels

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

    Projects

    Status

    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions