Skip to content

Commit 20fde53

Browse files
bpo-36436: Fix _testcapi.pymem_buffer_overflow() (GH-12560)
Handle memory allocation failure. (cherry picked from commit 414b1cd) Co-authored-by: Victor Stinner <vstinner@redhat.com>
1 parent 0344085 commit 20fde53

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix ``_testcapi.pymem_buffer_overflow()``: handle memory allocation failure.

Modules/_testcapimodule.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4175,6 +4175,10 @@ pymem_buffer_overflow(PyObject *self, PyObject *args)
41754175
/* Deliberate buffer overflow to check that PyMem_Free() detects
41764176
the overflow when debug hooks are installed. */
41774177
buffer = PyMem_Malloc(16);
4178+
if (buffer == NULL) {
4179+
PyErr_NoMemory();
4180+
return NULL;
4181+
}
41784182
buffer[16] = 'x';
41794183
PyMem_Free(buffer);
41804184

0 commit comments

Comments
 (0)