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.
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 @@
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 @@
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);