aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2013-07-15 20:00:36 +0200
committerVictor Stinner <victor.stinner@gmail.com>2013-07-15 20:00:36 +0200
commita4ced86f0307d60c491261501f53a99cefcc33d2 (patch)
treeff92d100b769700d35eee01bb4265f0d57d628b0 /Modules/_randommodule.c
parenttest_io: check_interrupted_write() now cancels the alarm if ZeroDivisionError (diff)
downloadcpython-a4ced86f0307d60c491261501f53a99cefcc33d2.tar.gz
cpython-a4ced86f0307d60c491261501f53a99cefcc33d2.tar.bz2
cpython-a4ced86f0307d60c491261501f53a99cefcc33d2.zip
Issue #18408: random_seed() now raises a MemoryError on memory allocation
failure
Diffstat (limited to 'Modules/_randommodule.c')
-rw-r--r--Modules/_randommodule.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/Modules/_randommodule.c b/Modules/_randommodule.c
index a729817f3dd..59c15b39d70 100644
--- a/Modules/_randommodule.c
+++ b/Modules/_randommodule.c
@@ -250,8 +250,10 @@ random_seed(RandomObject *self, PyObject *args)
/* Convert seed to byte sequence. */
key_as_bytes = (unsigned char *)PyMem_Malloc((size_t)4 * keyused);
- if (key_as_bytes == NULL)
+ if (key_as_bytes == NULL) {
+ PyErr_NoMemory();
goto Done;
+ }
res = _PyLong_AsByteArray((PyLongObject *)n,
key_as_bytes, keyused * 4,
1, /* little-endian */
@@ -264,6 +266,7 @@ random_seed(RandomObject *self, PyObject *args)
/* Fill array of unsigned longs from byte sequence. */
key = (unsigned long *)PyMem_Malloc(sizeof(unsigned long) * keyused);
if (key == NULL) {
+ PyErr_NoMemory();
PyMem_Free(key_as_bytes);
goto Done;
}