Skip to content

readline leaks the completer delimiters buffer on re-import #160353

Description

@ashm-dev

Bug report

Re-importing readline after removing it from sys.modules leaks the buffer allocated by set_completer_delims().

Reproduced on Linux with an AddressSanitizer build of CPython main, commit ad101c3 (3.16.0a1+dev):

  ASAN_OPTIONS=detect_leaks=1 ./python -I -S -B -c 'import readline, sys; readline.set_completer_delims("x" * 28); del sys.modules["readline"]; import readline'

LeakSanitizer reports 29 bytes leaked in one allocation, originating from strdup() in readline_set_completer_delims_impl() (Modules/readline.c:853).

During re-import, setup_readline() overwrites completer_word_break_characters with a new allocation without freeing the previous buffer. Repeated calls to set_completer_delims() without re-importing do not
reproduce the leak.

Related reports: #94064, #152398.

CPython versions tested on:

CPython main branch, 3.16, 3.15

Operating systems tested on:

Linux

Linked PRs

Activity

  1. picnixz commented on Oct 22, 2026

    @picnixz
    Member

    How is it related to #150536?

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

    extension-modulesC modules in the Modules dirtype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions