Skip to content

Commit 33b5aeb

Browse files
[3.14] gh-151842: Fix crash upon OOM in _interpreters.capture_exception (GH-151843) (GH-152032)
(cherry picked from commit 5e0747d) Co-authored-by: Amrutha <amruthamodela06@gmail.com>
1 parent 8f94785 commit 33b5aeb

3 files changed

Lines changed: 7 additions & 1 deletion

File tree

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix a crash in :func:`!_interpreters.capture_exception` when
2+
:exc:`MemoryError` happens. Patch by Amrutha Modela.

Modules/_interpretersmodule.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1580,7 +1580,9 @@ capture_exception(PyObject *self, PyObject *args, PyObject *kwds)
15801580
}
15811581

15821582
finally:
1583-
_PyXI_FreeExcInfo(info);
1583+
if (info != NULL) {
1584+
_PyXI_FreeExcInfo(info);
1585+
}
15841586
if (exc != exc_arg) {
15851587
if (PyErr_Occurred()) {
15861588
PyErr_SetRaisedException(exc);

Python/crossinterp.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1648,6 +1648,7 @@ _PyXI_NewExcInfo(PyObject *exc)
16481648
}
16491649
_PyXI_excinfo *info = PyMem_RawCalloc(1, sizeof(_PyXI_excinfo));
16501650
if (info == NULL) {
1651+
PyErr_NoMemory();
16511652
return NULL;
16521653
}
16531654
const char *failure;
@@ -1668,6 +1669,7 @@ _PyXI_NewExcInfo(PyObject *exc)
16681669
void
16691670
_PyXI_FreeExcInfo(_PyXI_excinfo *info)
16701671
{
1672+
assert(info != NULL);
16711673
_PyXI_excinfo_clear(info);
16721674
PyMem_RawFree(info);
16731675
}

0 commit comments

Comments
 (0)