summaryrefslogtreecommitdiff
path: root/Objects
diff options
context:
space:
mode:
authorKristjan Valur Jonsson <sweskman@gmail.com>2012-05-31 09:37:31 +0000
committerKristjan Valur Jonsson <sweskman@gmail.com>2012-05-31 09:37:31 +0000
commit7e4023785beea8974e7b3452ff0ae95a579be759 (patch)
tree7fda92f3b43864a7473041520d6ceea1cdc96750 /Objects
parent36e029cedd42e55cb4a44cb55143466f717f2e30 (diff)
downloadcpython-7e4023785beea8974e7b3452ff0ae95a579be759.tar.gz
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 'Objects')
-rw-r--r--Objects/frameobject.c6
-rw-r--r--Objects/unicodeobject.c6
2 files changed, 8 insertions, 4 deletions
diff --git a/Objects/frameobject.c b/Objects/frameobject.c
index 62085562e3..929385fe28 100644
--- a/Objects/frameobject.c
+++ b/Objects/frameobject.c
@@ -663,11 +663,13 @@ PyFrame_New(PyThreadState *tstate, PyCodeObject *code, PyObject *globals,
f = free_list;
free_list = free_list->f_back;
if (Py_SIZE(f) < extras) {
- f = PyObject_GC_Resize(PyFrameObject, f, extras);
- if (f == NULL) {
+ PyFrameObject *new_f = PyObject_GC_Resize(PyFrameObject, f, extras);
+ if (new_f == NULL) {
+ PyObject_GC_Del(f);
Py_DECREF(builtins);
return NULL;
}
+ f = new_f;
}
_Py_NewReference((PyObject *)f);
}
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
index 874e80e1dd..9e9378ef11 100644
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -8343,13 +8343,15 @@ charmaptranslate_makespace(Py_UCS4 **outobj, Py_ssize_t *psize,
Py_ssize_t requiredsize)
{
Py_ssize_t oldsize = *psize;
+ Py_UCS4 *new_outobj;
if (requiredsize > oldsize) {
/* exponentially overallocate to minimize reallocations */
if (requiredsize < 2 * oldsize)
requiredsize = 2 * oldsize;
- *outobj = PyMem_Realloc(*outobj, requiredsize * sizeof(Py_UCS4));
- if (*outobj == 0)
+ new_outobj = PyMem_Realloc(*outobj, requiredsize * sizeof(Py_UCS4));
+ if (new_outobj == 0)
return -1;
+ *outobj = new_outobj;
*psize = requiredsize;
}
return 0;