summaryrefslogtreecommitdiffstats
path: root/Python/symtable.c
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2013-07-11 20:49:00 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2013-07-11 20:49:00 (GMT)
commit9a4fb669668843de94c82c9e6de86a2ffa865eb7 (patch)
treede8b5cbb0cadd20ef413ffb87283ebceb76078f8 /Python/symtable.c
parent2e8474ddde61204b2671225cf4482dbc6fab4ea1 (diff)
downloadcpython-9a4fb669668843de94c82c9e6de86a2ffa865eb7.zip
cpython-9a4fb669668843de94c82c9e6de86a2ffa865eb7.tar.gz
cpython-9a4fb669668843de94c82c9e6de86a2ffa865eb7.tar.bz2
Issue #18408: ste_new() initialize all attributes before handling error
If an attribute is not initialized, the destructor can crash
Diffstat (limited to 'Python/symtable.c')
-rw-r--r--Python/symtable.c22
1 files changed, 9 insertions, 13 deletions
diff --git a/Python/symtable.c b/Python/symtable.c
index 758aefb..183bf69 100644
--- a/Python/symtable.c
+++ b/Python/symtable.c
@@ -37,25 +37,13 @@ ste_new(struct symtable *st, identifier name, _Py_block_ty block,
ste->ste_table = st;
ste->ste_id = k; /* ste owns reference to k */
- ste->ste_name = name;
Py_INCREF(name);
+ ste->ste_name = name;
ste->ste_symbols = NULL;
ste->ste_varnames = NULL;
ste->ste_children = NULL;
- ste->ste_symbols = PyDict_New();
- if (ste->ste_symbols == NULL)
- goto fail;
-
- ste->ste_varnames = PyList_New(0);
- if (ste->ste_varnames == NULL)
- goto fail;
-
- ste->ste_children = PyList_New(0);
- if (ste->ste_children == NULL)
- goto fail;
-
ste->ste_directives = NULL;
ste->ste_type = block;
@@ -79,6 +67,14 @@ ste_new(struct symtable *st, identifier name, _Py_block_ty block,
ste->ste_returns_value = 0;
ste->ste_needs_class_closure = 0;
+ ste->ste_symbols = PyDict_New();
+ ste->ste_varnames = PyList_New(0);
+ ste->ste_children = PyList_New(0);
+ if (ste->ste_symbols == NULL
+ || ste->ste_varnames == NULL
+ || ste->ste_children == NULL)
+ goto fail;
+
if (PyDict_SetItem(st->st_blocks, ste->ste_id, (PyObject *)ste) < 0)
goto fail;