Skip to content

Commit 6540493

Browse files
[3.12] gh-105375: Improve error handling in compiler_enter_scope() (GH-105494) (#105581)
(cherry picked from commit 6c832dd) Co-authored-by: Erlend E. Aasland <[email protected]>
1 parent bc365da commit 6540493

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix bug in the compiler where an exception could end up being overwritten.

Python/compile.c

+5-1
Original file line numberDiff line numberDiff line change
@@ -1252,8 +1252,12 @@ compiler_enter_scope(struct compiler *c, identifier name,
12521252
}
12531253
u->u_metadata.u_name = Py_NewRef(name);
12541254
u->u_metadata.u_varnames = list2dict(u->u_ste->ste_varnames);
1255+
if (!u->u_metadata.u_varnames) {
1256+
compiler_unit_free(u);
1257+
return ERROR;
1258+
}
12551259
u->u_metadata.u_cellvars = dictbytype(u->u_ste->ste_symbols, CELL, DEF_COMP_CELL, 0);
1256-
if (!u->u_metadata.u_varnames || !u->u_metadata.u_cellvars) {
1260+
if (!u->u_metadata.u_cellvars) {
12571261
compiler_unit_free(u);
12581262
return ERROR;
12591263
}

0 commit comments

Comments
 (0)