From: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> Date: Fri, 9 Jun 2023 17:23:45 +0000 (-0700) Subject: [3.12] gh-105375: Improve error handling in compiler_enter_scope() (GH-105494) (... X-Git-Tag: v3.12.0b3~63 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=65404930bdfcc3755eee70673ed0f592e5fcb37e;p=thirdparty%2FPython%2Fcpython.git [3.12] gh-105375: Improve error handling in compiler_enter_scope() (GH-105494) (#105581) (cherry picked from commit 6c832ddcf28187f86100c790afb16a0223d945d0) Co-authored-by: Erlend E. Aasland --- diff --git a/Misc/NEWS.d/next/Core and Builtins/2023-06-08-09-54-37.gh-issue-105375.kqKT3E.rst b/Misc/NEWS.d/next/Core and Builtins/2023-06-08-09-54-37.gh-issue-105375.kqKT3E.rst new file mode 100644 index 000000000000..b4d3a1a5a3ce --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2023-06-08-09-54-37.gh-issue-105375.kqKT3E.rst @@ -0,0 +1 @@ +Fix bug in the compiler where an exception could end up being overwritten. diff --git a/Python/compile.c b/Python/compile.c index 32eda4d407ea..f593e957caae 100644 --- a/Python/compile.c +++ b/Python/compile.c @@ -1252,8 +1252,12 @@ compiler_enter_scope(struct compiler *c, identifier name, } u->u_metadata.u_name = Py_NewRef(name); u->u_metadata.u_varnames = list2dict(u->u_ste->ste_varnames); + if (!u->u_metadata.u_varnames) { + compiler_unit_free(u); + return ERROR; + } u->u_metadata.u_cellvars = dictbytype(u->u_ste->ste_symbols, CELL, DEF_COMP_CELL, 0); - if (!u->u_metadata.u_varnames || !u->u_metadata.u_cellvars) { + if (!u->u_metadata.u_cellvars) { compiler_unit_free(u); return ERROR; }