gh-146250: Fix memory leak in re-initialization of SyntaxError#146251
Open
bkap123 wants to merge 3 commits intopython:mainfrom
Open
gh-146250: Fix memory leak in re-initialization of SyntaxError#146251bkap123 wants to merge 3 commits intopython:mainfrom
SyntaxError#146251bkap123 wants to merge 3 commits intopython:mainfrom
Conversation
Added `Py_XDECREF`/`Py_XSETREF` to avoid a memory leak when calling `SyntaxError.__init__`.
aisk
reviewed
Mar 21, 2026
Misc/NEWS.d/next/Core_and_Builtins/2026-03-21-11-55-16.gh-issue-146250.ahl3O2.rst
Outdated
Show resolved
Hide resolved
picnixz
reviewed
Mar 21, 2026
| self.assertGreater(len(output), 0) # At minimum, should not hang | ||
| self.assertIn(b"MemoryError", output) | ||
|
|
||
| # gh-146250: memory leak with re-initialization of SyntaxError |
Member
There was a problem hiding this comment.
Put this comment in the test instead above it.
Comment on lines
+2805
to
+2808
| Py_XDECREF(self->filename); | ||
| Py_XDECREF(self->lineno); | ||
| Py_XDECREF(self->offset); | ||
| Py_XDECREF(self->text); |
Member
There was a problem hiding this comment.
I think we should instead create temp vara and use XSETREF, as we do for AttributeError. It would be much cleaner.
Co-authored-by: AN Long <aisk@users.noreply.github.com> Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Member
|
Sorry about the Py_CLEAR suggestion but I think creating new variables would be cleaner. |
Contributor
Author
|
What's wrong with using |
Member
|
I think it is just better to hold temp vars and use XSETREF like in |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Added
Py_XDECREF/Py_XSETREFto avoid a memory leak when callingSyntaxError.__init__.SyntaxError.__init__memory leak on re-initialization #146250