From 73d4a2692860fb1312697d9802e22a2eb5a87520 Mon Sep 17 00:00:00 2001 From: "Erlend E. Aasland" Date: Fri, 9 Jun 2023 18:55:53 +0200 Subject: [PATCH] [3.11] gh-105375: Improve error handling in compiler_enter_scope() (#105494) --- .../2023-06-08-09-54-37.gh-issue-105375.kqKT3E.rst | 1 + Python/compile.c | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 Misc/NEWS.d/next/Core and Builtins/2023-06-08-09-54-37.gh-issue-105375.kqKT3E.rst 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 00000000000000..b4d3a1a5a3cedb --- /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 5f26da8608a477..9b71451ac80608 100644 --- a/Python/compile.c +++ b/Python/compile.c @@ -1736,8 +1736,12 @@ compiler_enter_scope(struct compiler *c, identifier name, Py_INCREF(name); u->u_name = name; u->u_varnames = list2dict(u->u_ste->ste_varnames); + if (!u->u_varnames) { + compiler_unit_free(u); + return ERROR; + } u->u_cellvars = dictbytype(u->u_ste->ste_symbols, CELL, 0, 0); - if (!u->u_varnames || !u->u_cellvars) { + if (!u->u_cellvars) { compiler_unit_free(u); return 0; }