Skip to content

Commit 90e357b

Browse files
[3.11] gh-105375: Improve error handling in compiler_enter_scope() (#105494) (#105582)
(cherry picked from commit 6c832dd) Co-authored-by: Erlend E. Aasland <[email protected]>
1 parent c28887d commit 90e357b

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed
Lines changed: 1 addition & 0 deletions
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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1736,8 +1736,12 @@ compiler_enter_scope(struct compiler *c, identifier name,
17361736
Py_INCREF(name);
17371737
u->u_name = name;
17381738
u->u_varnames = list2dict(u->u_ste->ste_varnames);
1739+
if (!u->u_varnames) {
1740+
compiler_unit_free(u);
1741+
return 0;
1742+
}
17391743
u->u_cellvars = dictbytype(u->u_ste->ste_symbols, CELL, 0, 0);
1740-
if (!u->u_varnames || !u->u_cellvars) {
1744+
if (!u->u_cellvars) {
17411745
compiler_unit_free(u);
17421746
return 0;
17431747
}

0 commit comments

Comments
 (0)