summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
Diffstat (limited to 'Objects')
-rw-r--r--Objects/codeobject.c24
1 files changed, 14 insertions, 10 deletions
diff --git a/Objects/codeobject.c b/Objects/codeobject.c
index b1e8ec9..ebc7066 100644
--- a/Objects/codeobject.c
+++ b/Objects/codeobject.c
@@ -861,16 +861,15 @@ _PyCode_SetExtra(PyObject *code, Py_ssize_t index, void *extra)
_PyCodeObjectExtra *co_extra = (_PyCodeObjectExtra *) o->co_extra;
if (co_extra == NULL) {
- o->co_extra = (_PyCodeObjectExtra*) PyMem_Malloc(
- sizeof(_PyCodeObjectExtra));
- if (o->co_extra == NULL) {
+ co_extra = PyMem_Malloc(sizeof(_PyCodeObjectExtra));
+ if (co_extra == NULL) {
return -1;
}
- co_extra = (_PyCodeObjectExtra *) o->co_extra;
co_extra->ce_extras = PyMem_Malloc(
tstate->co_extra_user_count * sizeof(void*));
if (co_extra->ce_extras == NULL) {
+ PyMem_Free(co_extra);
return -1;
}
@@ -879,20 +878,25 @@ _PyCode_SetExtra(PyObject *code, Py_ssize_t index, void *extra)
for (Py_ssize_t i = 0; i < co_extra->ce_size; i++) {
co_extra->ce_extras[i] = NULL;
}
+
+ o->co_extra = co_extra;
}
else if (co_extra->ce_size <= index) {
- co_extra->ce_extras = PyMem_Realloc(
+ void** ce_extras = PyMem_Realloc(
co_extra->ce_extras, tstate->co_extra_user_count * sizeof(void*));
- if (co_extra->ce_extras == NULL) {
+ if (ce_extras == NULL) {
return -1;
}
- co_extra->ce_size = tstate->co_extra_user_count;
-
- for (Py_ssize_t i = co_extra->ce_size; i < co_extra->ce_size; i++) {
- co_extra->ce_extras[i] = NULL;
+ for (Py_ssize_t i = co_extra->ce_size;
+ i < tstate->co_extra_user_count;
+ i++) {
+ ce_extras[i] = NULL;
}
+
+ co_extra->ce_extras = ce_extras;
+ co_extra->ce_size = tstate->co_extra_user_count;
}
co_extra->ce_extras[index] = extra;