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 — `SyntaxError.__init__` memory leak on re-initialization · Issue #146250 · python/cpython

SyntaxError.__init__ memory leak on re-initialization #146250

New issue
Copy link
New issue
Copy link
Closed
Closed
SyntaxError.__init__ memory leak on re-initialization#146250
Copy link
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Description

@brijkapadia
brijkapadia
opened on Mar 21, 2026
Issue body actions

Bug report

Bug description:

This is a sub-issue for #146102 and more information can be found here`.


When re-initializing a SyntaxError (by calling its __init__ method), it currently does not decref its prior values. This reproducer crashes with ASan:

e = SyntaxError("msg", ("file.py", 1, 2, "txt", 2, 3))
e.__init__("new_msg", ("new_file.py", 2, 3, "new_txt", 3, 4))
ASan report

=================================================================
==576215==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 72 byte(s) in 1 object(s) allocated from:
    #0 0x7fb60c520cb5 in malloc (/usr/lib/libasan.so.8+0x120cb5) (BuildId: 0b96d08695bbce2da9d4770c29ad2e72fb536f47)
    #1 0x5600a9805972 in _PyMem_RawMalloc Objects/obmalloc.c:65
    #2 0x5600a9804d63 in _PyMem_DebugRawAlloc Objects/obmalloc.c:3043
    #3 0x5600a9804dc7 in _PyMem_DebugRawMalloc Objects/obmalloc.c:3076
    #4 0x5600a9806748 in _PyMem_DebugMalloc Objects/obmalloc.c:3241
    #5 0x5600a982ecf3 in PyObject_Malloc Objects/obmalloc.c:1649
    #6 0x5600a98cdf45 in PyUnicode_New Objects/unicodeobject.c:1318
    #7 0x5600a98d3471 in unicode_decode_utf8 Objects/unicodeobject.c:5273
    #8 0x5600a98df566 in PyUnicode_DecodeUTF8Stateful Objects/unicodeobject.c:5381
    #9 0x5600a96eeb3b in _PyPegen_decode_string Parser/string_parser.c:245
    #10 0x5600a96ef0b0 in _PyPegen_parse_string Parser/string_parser.c:338
    #11 0x5600a95ce09e in _PyPegen_constant_from_string Parser/action_helpers.c:1480
    #12 0x5600a95e9b7a in string_rule Parser/parser.c:17349
    #13 0x5600a963ed92 in _tmp_156_rule Parser/parser.c:37961
    #14 0x5600a963f435 in _loop1_82_rule Parser/parser.c:33521
    #15 0x5600a96486ab in strings_rule Parser/parser.c:17420
    #16 0x5600a9605530 in atom_rule Parser/parser.c:15361
    #17 0x5600a9607dce in primary_raw Parser/parser.c:14999
    #18 0x5600a96083ed in primary_rule Parser/parser.c:14797
    #19 0x5600a9608da2 in await_primary_rule Parser/parser.c:14751
    #20 0x5600a960934c in power_rule Parser/parser.c:14627
    #21 0x5600a960af00 in factor_rule Parser/parser.c:14577
    #22 0x5600a960d6b4 in term_raw Parser/parser.c:14418
    #23 0x5600a960dcd3 in term_rule Parser/parser.c:14161
    #24 0x5600a960e9e5 in sum_raw Parser/parser.c:14114
    #25 0x5600a960f037 in sum_rule Parser/parser.c:13993
    #26 0x5600a9610687 in shift_expr_raw Parser/parser.c:13953
    #27 0x5600a9610cd9 in shift_expr_rule Parser/parser.c:13813
    #28 0x5600a9611502 in bitwise_and_raw Parser/parser.c:13773
    #29 0x5600a9611b54 in bitwise_and_rule Parser/parser.c:13691

SUMMARY: AddressSanitizer: 72 byte(s) leaked in 1 allocation(s).

The fix is to call Py_XDECREF before replacing the entries in the SyntaxError object.

CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

Linked PRs

  • gh-146250: Fix memory leak in re-initialization of SyntaxError #146251
  • [3.14] gh-146250: Fix memory leak in re-initialization of SyntaxError (GH-146251) #146517
  • [3.13] gh-146250: Fix memory leak in re-initialization of SyntaxError (GH-146251) #146519

Activity

  1. brijkapadia
    added
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    on Mar 21, 2026
  2. brijkapadia
    added a commit that references this issue on Mar 21, 2026

    pythongh-146250: Fix memory leak of re-initialization of `SyntaxError`

    9370f4f
  3. aisk
    added a parent issue on Mar 21, 2026
    • Umbrella issue: bugs found using cpython-review-toolkit #146102
  4. picnixz
    added
    interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)
    on Mar 21, 2026
  5. kumaraditya303
    added a commit that references this issue on Mar 27, 2026

    gh-146250: Fix memory leak in re-initialization of `SyntaxError` (#14…

    0de4e08
  6. miss-islington
    added a commit that references this issue on Mar 27, 2026

    pythongh-146250: Fix memory leak in re-initialization of `SyntaxError` (

    fcb10a5
  7. kumaraditya303
    closed this as completedon Mar 27, 2026
  8. kumaraditya303
    added a commit that references this issue on Mar 30, 2026

    [3.13] gh-146250: Fix memory leak in re-initialization of `SyntaxErro…

    c09ccd9
  9. hugovk
    added a commit that references this issue on Mar 30, 2026

    [3.14] gh-146250: Fix memory leak in re-initialization of `SyntaxErro…

    3c434f7
  10. clin1234
    added a commit that references this issue on Apr 16, 2026

    pythongh-146250: Fix memory leak in re-initialization of `SyntaxError` (

    d8f9f4b
  11. ljfp
    added a commit that references this issue on Apr 25, 2026

    pythongh-146250: Fix memory leak in re-initialization of `SyntaxError` (

    b723bfa
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)(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

    Projects

    No projects

      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.