Skip to content

PyInitConfig_Free() doesn't release memory allocated by PyInitConfig_SetStr() #138756

Description

@vstinner

Bug report

Bug description:

When building Python with address sanitizer ./configure --with-pydebug --with-address-sanitizer CFLAGS="-O0", the build fails with the following error:

==768783==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 68 byte(s) in 1 object(s) allocated from:
    #0 0x7fd85a0e6f2b in malloc (/lib64/libasan.so.8+0xe6f2b) (BuildId: 10b8ccd49f75c21babf1d7abe51bb63589d8471f)
    #1 0x000000a8a258 in utf8_to_wstr Python/initconfig.c:4054
    #2 0x000000a8a643 in PyInitConfig_SetStr Python/initconfig.c:4088
    #3 0x00000040238d in runtime_init Programs/_freeze_module.c:57
    #4 0x0000004030ee in main Programs/_freeze_module.c:237
    #5 0x7fd859e11574 in __libc_start_call_main (/lib64/libc.so.6+0x3574) (BuildId: 48c4b9b1efb1df15da8e787f489128bf31893317)
    #6 0x7fd859e11627 in __libc_start_main@GLIBC_2.2.5 (/lib64/libc.so.6+0x3627) (BuildId: 48c4b9b1efb1df15da8e787f489128bf31893317)
    #7 0x000000401eb4 in _start (/home/vstinner/python/main/Programs/_freeze_module+0x401eb4) (BuildId: 871b1eb54b816428317fe79f8100da96490cf4fc)

SUMMARY: AddressSanitizer: 68 byte(s) leaked in 1 allocation(s).
make: *** [Makefile:1937: Python/frozen_modules/importlib._bootstrap_external.h] Error 1

The problem is that the PyInitConfig C API leaks memory. PyInitConfig_Free() doesn't release memory allocated by PyInitConfig_SetStr().

CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

Linked PRs

Activity

  1. added a commit that references this issue on Sep 10, 2025
  2. added a commit that references this issue on Sep 11, 2025
  3. added a commit that references this issue on Sep 11, 2025
  4. added a commit that references this issue on Sep 11, 2025
  5. added a commit that references this issue on Sep 12, 2025
  6. added a commit that references this issue on Oct 7, 2025
  7. added a commit that references this issue on Oct 7, 2025
  8. added a commit that references this issue on Oct 7, 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

    interpreter-core(Objects, Python, Grammar, and Parser dirs)topic-C-APItype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions