gh-151673: Fix crash in warnings.warn() under memory pressure#151767
Open
Ijtihed wants to merge 1 commit into
Open
gh-151673: Fix crash in warnings.warn() under memory pressure#151767Ijtihed wants to merge 1 commit into
Ijtihed wants to merge 1 commit into
Conversation
Author
|
the ci failure was preexisting on main. i can update branch when needed |
| """ | ||
| rc, out, err = assert_python_failure("-c", code) | ||
| self.assertIn(rc, (1, 120)) | ||
| self.assertIn(b'MemoryError', err) |
Member
There was a problem hiding this comment.
Can we not make this a try/except?
Author
There was a problem hiding this comment.
skip is now handled inside the test trough import_helper.import_module
| # Python built with Py_TRACE_REFS fail with a fatal error in | ||
| # _PyRefchain_Trace() on memory allocation error. | ||
| @unittest.skipIf(support.Py_TRACE_REFS, 'cannot test Py_TRACE_REFS build') | ||
| @unittest.skipIf(_testcapi is None, "requires _testcapi") |
Member
There was a problem hiding this comment.
This can be simplified to running:
# Skip this test if the _testcapi module isn't available.
_testcapi = import_helper.import_module('_testcapi')
In the test.
6866bc9 to
e01d44b
Compare
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.
When
warnings.warn()runs while every allocation is failingsetup_context()took thef == NULLbranch and calledPyUnicode_FromString("<sys>")without checking the result. The resulting NULL filename was then passed toPy_DECREFeither bydo_warn()on the success path or bysetup_context()'s ownhandle_error:label (which usedPy_DECREF, notPy_XDECREF). This caused a segfault.The fix initialize the output references up front then check the
"<sys>"allocation and usePy_XDECREFin the error path.Fixes #151673
Py_DECREF(NULL)insetup_context/do_warn(_warnings.c) when emitting a warning under MemoryError #151673