gh-148058: Do not refleak when XMLParser.__init__() called many times#148061
Closed
maurycy wants to merge 5 commits intopython:mainfrom
Closed
gh-148058: Do not refleak when XMLParser.__init__() called many times#148061maurycy wants to merge 5 commits intopython:mainfrom
XMLParser.__init__() called many times#148061maurycy wants to merge 5 commits intopython:mainfrom
Conversation
XMLParser.__init__() called many timesXMLParser.__init__() called many times
picnixz
reviewed
Apr 4, 2026
Member
picnixz
left a comment
There was a problem hiding this comment.
I am not convinced by this check. I would rather prefer that we decide first what to do with re-init being called in general rather than fixing them case by case. I think other C classes are subject to this issue.
Comment on lines
+3718
to
+3719
| if (self->parser != NULL) { | ||
| (void)xmlparser_gc_clear((PyObject *)self); |
Member
There was a problem hiding this comment.
I would prefer rejecting this rather than fixing it. If there is no crash issues, I would rather not fix it at all.
Member
|
For XML parsers, I would rather hard reject re-init. Because there mighr be a way to do bad stuff if the parser is still a parent of someone else, isn't there? |
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.
XMLParser.__init__()refleaks when called many times. See gh-148058 for more details. Thankfully, there's alreadyxmlparser_gc_clear.I copied the test pattern from:
cpython/Lib/test/test_csv.py
Line 1541 in e7bf8ea
cpython/Lib/test/test_zlib.py
Line 1211 in dea4083
cpython/Lib/test/test_lzma.py
Line 374 in dea4083
etc.
The test failed on
main: