Title: `SyntaxError.__init__` memory leak on re-initialization · Issue #146250 · python/cpython · GitHub
Open Graph Title: `SyntaxError.__init__` memory leak on re-initialization · Issue #146250 · python/cpython
X Title: `SyntaxError.__init__` memory leak on re-initialization · Issue #146250 · python/cpython
Description: 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 cras...
Open Graph Description: 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 decre...
X Description: 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 decre...
Opengraph URL: https://github.com/python/cpython/issues/146250
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"`SyntaxError.__init__` memory leak on re-initialization","articleBody":"# Bug report\n\n### Bug description:\n\nThis is a sub-issue for #146102 and more information can be found [here`](https://gist.github.com/devdanzin/1c1e9ba549c26332c387b23406c84ad5).\n\n---\n\nWhen re-initializing a `SyntaxError` (by calling its `__init__` method), it currently does not decref its prior values. This reproducer crashes with ASan:\n```python \ne = SyntaxError(\"msg\", (\"file.py\", 1, 2, \"txt\", 2, 3))\ne.__init__(\"new_msg\", (\"new_file.py\", 2, 3, \"new_txt\", 3, 4))\n\n```\n\n\u003cdetails\u003e\u003csummary\u003eASan report\u003c/summary\u003e\n\u003cp\u003e\n\n```shell\n\n=================================================================\n==576215==ERROR: LeakSanitizer: detected memory leaks\n\nDirect leak of 72 byte(s) in 1 object(s) allocated from:\n #0 0x7fb60c520cb5 in malloc (/usr/lib/libasan.so.8+0x120cb5) (BuildId: 0b96d08695bbce2da9d4770c29ad2e72fb536f47)\n #1 0x5600a9805972 in _PyMem_RawMalloc Objects/obmalloc.c:65\n #2 0x5600a9804d63 in _PyMem_DebugRawAlloc Objects/obmalloc.c:3043\n #3 0x5600a9804dc7 in _PyMem_DebugRawMalloc Objects/obmalloc.c:3076\n #4 0x5600a9806748 in _PyMem_DebugMalloc Objects/obmalloc.c:3241\n #5 0x5600a982ecf3 in PyObject_Malloc Objects/obmalloc.c:1649\n #6 0x5600a98cdf45 in PyUnicode_New Objects/unicodeobject.c:1318\n #7 0x5600a98d3471 in unicode_decode_utf8 Objects/unicodeobject.c:5273\n #8 0x5600a98df566 in PyUnicode_DecodeUTF8Stateful Objects/unicodeobject.c:5381\n #9 0x5600a96eeb3b in _PyPegen_decode_string Parser/string_parser.c:245\n #10 0x5600a96ef0b0 in _PyPegen_parse_string Parser/string_parser.c:338\n #11 0x5600a95ce09e in _PyPegen_constant_from_string Parser/action_helpers.c:1480\n #12 0x5600a95e9b7a in string_rule Parser/parser.c:17349\n #13 0x5600a963ed92 in _tmp_156_rule Parser/parser.c:37961\n #14 0x5600a963f435 in _loop1_82_rule Parser/parser.c:33521\n #15 0x5600a96486ab in strings_rule Parser/parser.c:17420\n #16 0x5600a9605530 in atom_rule Parser/parser.c:15361\n #17 0x5600a9607dce in primary_raw Parser/parser.c:14999\n #18 0x5600a96083ed in primary_rule Parser/parser.c:14797\n #19 0x5600a9608da2 in await_primary_rule Parser/parser.c:14751\n #20 0x5600a960934c in power_rule Parser/parser.c:14627\n #21 0x5600a960af00 in factor_rule Parser/parser.c:14577\n #22 0x5600a960d6b4 in term_raw Parser/parser.c:14418\n #23 0x5600a960dcd3 in term_rule Parser/parser.c:14161\n #24 0x5600a960e9e5 in sum_raw Parser/parser.c:14114\n #25 0x5600a960f037 in sum_rule Parser/parser.c:13993\n #26 0x5600a9610687 in shift_expr_raw Parser/parser.c:13953\n #27 0x5600a9610cd9 in shift_expr_rule Parser/parser.c:13813\n #28 0x5600a9611502 in bitwise_and_raw Parser/parser.c:13773\n #29 0x5600a9611b54 in bitwise_and_rule Parser/parser.c:13691\n\nSUMMARY: AddressSanitizer: 72 byte(s) leaked in 1 allocation(s).\n\n``` \n\n\u003c/p\u003e\n\u003c/details\u003e \n\nThe fix is to call `Py_XDECREF` before replacing the entries in the `SyntaxError` object.\n\n### CPython versions tested on:\n\nCPython main branch\n\n### Operating systems tested on:\n\nLinux\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-146251\n* gh-146517\n* gh-146519\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/brijkapadia","@type":"Person","name":"brijkapadia"},"datePublished":"2026-03-21T11:42:21.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/146250/cpython/issues/146250"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:4074ab34-863f-b49e-f185-f913633fdeb3 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | BF5A:82FD0:AC5282F:AFBFBA9:6A50BA6B |
| html-safe-nonce | 5edb0d4561ed8a9f094afa4d3ceb5f8db8c36929c1107ee95edf32ee134a79ec |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCRjVBOjgyRkQwOkFDNTI4MkY6QUZCRkJBOTo2QTUwQkE2QiIsInZpc2l0b3JfaWQiOiI4NzczODg0NjExMzkyNDg1OTk1IiwicmVnaW9uX2VkZ2UiOiJzZWEiLCJyZWdpb25fcmVuZGVyIjoic2VhIn0= |
| visitor-hmac | 9cd5514bd3e6fd2fbc1450dc7954d16abd20b59216d6760bb91bfc9fbb62c3e8 |
| hovercard-subject-tag | issue:4112210711 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/146250/issue_layout |
| twitter:image | https://opengraph.githubassets.com/ed9c4fdcb4dc37c683f74db1f2835ac9c1e4acc4d7805e8baaf8aa27dd2bcc00/python/cpython/issues/146250 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/ed9c4fdcb4dc37c683f74db1f2835ac9c1e4acc4d7805e8baaf8aa27dd2bcc00/python/cpython/issues/146250 |
| og:image:alt | 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 decre... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | brijkapadia |
| hostname | github.com |
| expected-hostname | github.com |
| None | 63772747707af4093f0d5fc7aa1bb3bb55f412a9865207c4f421aa34c64cc404 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | ded53fe94e3ff1bb4dbf8cc77e285396c92580fb |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width