Commit 9a4fb669 authored by Victor Stinner's avatar Victor Stinner

Issue #18408: ste_new() initialize all attributes before handling error

If an attribute is not initialized, the destructor can crash
parent 2e8474dd
...@@ -37,25 +37,13 @@ ste_new(struct symtable *st, identifier name, _Py_block_ty block, ...@@ -37,25 +37,13 @@ ste_new(struct symtable *st, identifier name, _Py_block_ty block,
ste->ste_table = st; ste->ste_table = st;
ste->ste_id = k; /* ste owns reference to k */ ste->ste_id = k; /* ste owns reference to k */
ste->ste_name = name;
Py_INCREF(name); Py_INCREF(name);
ste->ste_name = name;
ste->ste_symbols = NULL; ste->ste_symbols = NULL;
ste->ste_varnames = NULL; ste->ste_varnames = NULL;
ste->ste_children = 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_directives = NULL;
ste->ste_type = block; ste->ste_type = block;
...@@ -79,6 +67,14 @@ ste_new(struct symtable *st, identifier name, _Py_block_ty block, ...@@ -79,6 +67,14 @@ ste_new(struct symtable *st, identifier name, _Py_block_ty block,
ste->ste_returns_value = 0; ste->ste_returns_value = 0;
ste->ste_needs_class_closure = 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) if (PyDict_SetItem(st->st_blocks, ste->ste_id, (PyObject *)ste) < 0)
goto fail; goto fail;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment