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:
|
r = PyRun_SimpleStringFlags(code, &cflags); |
(run_in_subinterp)
Module initialization:
|
if (init_state(state) < 0) { |
(init__testsinglephase_basic)
|
state->error = PyErr_NewException("_testsinglephase.error", NULL, NULL); |
(init_state with PyErr_NewException)
Import machinery:
-
(_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
Bug report
Bug description:
LeakSanitizer detects memory leaks when running
test_importwith the_testsinglephasemodule loaded in a subinterpreter.How to Reproduce
Build:
Run:
./python -X dev -X showrefcount -m test test_import -j0Leak Summary
Code Locations
The leaks originate from:
Subinterpreter execution:
cpython/Modules/_testcapimodule.c
Line 1223 in e8e0f41
(
run_in_subinterp)Module initialization:
cpython/Modules/_testsinglephase.c
Line 516 in e8e0f41
(
init__testsinglephase_basic)cpython/Modules/_testsinglephase.c
Line 303 in e8e0f41
(
init_statewithPyErr_NewException)Import machinery:
cpython/Python/importdl.c
Line 429 in e8e0f41
(
_PyImport_RunModInitFunc)Leaked Objects
type_new→PyErr_NewExceptionnew_keys_object→PyDict_SetItemStringPyModule_AddFunctionsFull Output
See attached
.logfiles 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