Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion Lib/test/test_exception_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import unittest
from test.support import (skip_emscripten_stack_overflow,
skip_wasi_stack_overflow, run_with_limited_c_stack,
exceeds_recursion_limit)
exceeds_recursion_limit, nomemtest)

class TestExceptionGroupTypeHierarchy(unittest.TestCase):
def test_exception_group_types(self):
Expand Down Expand Up @@ -130,6 +130,15 @@ class MyBEG(BaseExceptionGroup):
type(MyBEG("eg", [ValueError(12), KeyboardInterrupt(42)])),
MyBEG)

@nomemtest
def test_no_memory(self):
import _testcapi
# A tuple of exceptions is not copied, so the first allocation
# is the one of the exception group itself.
excs = (ValueError(1),)
with self.assertRaises(MemoryError):
_testcapi.call_with_nomemory(0, 0, ExceptionGroup, "eg", excs)


class StrAndReprTests(unittest.TestCase):
def test_ExceptionGroup(self):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Fix a crash in a debug build when creating an :exc:`ExceptionGroup` or
:exc:`BaseExceptionGroup` fails with :exc:`MemoryError`. Patch by Christian
Aurich Zanettini Martins.
6 changes: 3 additions & 3 deletions Objects/exceptions.c
Original file line number Diff line number Diff line change
Expand Up @@ -990,11 +990,11 @@ BaseExceptionGroup_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
*/
cls = (PyTypeObject*)PyExc_BaseExceptionGroup;
}
PyBaseExceptionGroupObject *self =
PyBaseExceptionGroupObject_CAST(BaseException_new(cls, args, kwds));
if (!self) {
PyObject *op = BaseException_new(cls, args, kwds);
if (!op) {
goto error;
}
PyBaseExceptionGroupObject *self = PyBaseExceptionGroupObject_CAST(op);

self->msg = Py_NewRef(message);
self->excs = exceptions;
Expand Down
Loading