diff options
author | Kristjan Valur Jonsson <sweskman@gmail.com> | 2012-05-31 09:37:31 (GMT) |
---|---|---|
committer | Kristjan Valur Jonsson <sweskman@gmail.com> | 2012-05-31 09:37:31 (GMT) |
commit | 85634d7a2e4b864c4ca3baa591e9479ffd5a2540 (patch) | |
tree | fda37abce087013b6b52f85a19a4ff33c1b13dce /Modules/_randommodule.c | |
parent | 56517e5cb91c896024934a520d365d6e275eb1ad (diff) | |
download | cpython-85634d7a2e4b864c4ca3baa591e9479ffd5a2540.zip cpython-85634d7a2e4b864c4ca3baa591e9479ffd5a2540.tar.gz cpython-85634d7a2e4b864c4ca3baa591e9479ffd5a2540.tar.bz2 |
Issue #14909: A number of places were using PyMem_Realloc() apis and
PyObject_GC_Resize() with incorrect error handling. In case of errors,
the original object would be leaked. This checkin fixes those cases.
Diffstat (limited to 'Modules/_randommodule.c')
-rw-r--r-- | Modules/_randommodule.c | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/Modules/_randommodule.c b/Modules/_randommodule.c index bc9b04a..3c7d700 100644 --- a/Modules/_randommodule.c +++ b/Modules/_randommodule.c @@ -210,7 +210,7 @@ random_seed(RandomObject *self, PyObject *args) PyObject *masklower = NULL; PyObject *thirtytwo = NULL; PyObject *n = NULL; - unsigned long *key = NULL; + unsigned long *new_key, *key = NULL; unsigned long keymax; /* # of allocated slots in key */ unsigned long keyused; /* # of used slots in key */ int err; @@ -287,10 +287,11 @@ random_seed(RandomObject *self, PyObject *args) PyErr_NoMemory(); goto Done; } - key = (unsigned long *)PyMem_Realloc(key, + new_key = (unsigned long *)PyMem_Realloc(key, bigger * sizeof(*key)); - if (key == NULL) + if (new_key == NULL) goto Done; + key = new_key; keymax = bigger; } assert(keyused < keymax); |