Skip to content

Commit 9a4fb66

Browse files
committed
Issue #18408: ste_new() initialize all attributes before handling error
If an attribute is not initialized, the destructor can crash
1 parent 2e8474d commit 9a4fb66

File tree

1 file changed

+9
-13
lines changed

1 file changed

+9
-13
lines changed

Python/symtable.c

+9-13
Original file line numberDiff line numberDiff line change
@@ -37,25 +37,13 @@ ste_new(struct symtable *st, identifier name, _Py_block_ty block,
3737
ste->ste_table = st;
3838
ste->ste_id = k; /* ste owns reference to k */
3939

40-
ste->ste_name = name;
4140
Py_INCREF(name);
41+
ste->ste_name = name;
4242

4343
ste->ste_symbols = NULL;
4444
ste->ste_varnames = NULL;
4545
ste->ste_children = NULL;
4646

47-
ste->ste_symbols = PyDict_New();
48-
if (ste->ste_symbols == NULL)
49-
goto fail;
50-
51-
ste->ste_varnames = PyList_New(0);
52-
if (ste->ste_varnames == NULL)
53-
goto fail;
54-
55-
ste->ste_children = PyList_New(0);
56-
if (ste->ste_children == NULL)
57-
goto fail;
58-
5947
ste->ste_directives = NULL;
6048

6149
ste->ste_type = block;
@@ -79,6 +67,14 @@ ste_new(struct symtable *st, identifier name, _Py_block_ty block,
7967
ste->ste_returns_value = 0;
8068
ste->ste_needs_class_closure = 0;
8169

70+
ste->ste_symbols = PyDict_New();
71+
ste->ste_varnames = PyList_New(0);
72+
ste->ste_children = PyList_New(0);
73+
if (ste->ste_symbols == NULL
74+
|| ste->ste_varnames == NULL
75+
|| ste->ste_children == NULL)
76+
goto fail;
77+
8278
if (PyDict_SetItem(st->st_blocks, ste->ste_id, (PyObject *)ste) < 0)
8379
goto fail;
8480

0 commit comments

Comments
 (0)