From 592575ca7a6f3892eafb5fe305a15d3dfee61be8 Mon Sep 17 00:00:00 2001 From: "Miss Islington (bot)" <31488909+miss-islington@users.noreply.github.com> Date: Sat, 27 Jun 2026 17:28:27 +0200 Subject: [PATCH] [3.15] gh-151126: Sets missing exceptions in `tkinter` and `socket` modules initializations (GH-152418) (#152420) gh-151126: Sets missing exceptions in `tkinter` and `socket` modules initializations (GH-152418) (cherry picked from commit a9fa8560143098168e0380386acbf4846c37472b) Co-authored-by: sobolevn --- .../next/Library/2026-06-27-17-19-09.gh-issue-151126.huUyOM.rst | 2 ++ Modules/_tkinter.c | 2 +- Modules/socketmodule.c | 1 + 3 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 Misc/NEWS.d/next/Library/2026-06-27-17-19-09.gh-issue-151126.huUyOM.rst diff --git a/Misc/NEWS.d/next/Library/2026-06-27-17-19-09.gh-issue-151126.huUyOM.rst b/Misc/NEWS.d/next/Library/2026-06-27-17-19-09.gh-issue-151126.huUyOM.rst new file mode 100644 index 00000000000..2e51fd45b59 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2026-06-27-17-19-09.gh-issue-151126.huUyOM.rst @@ -0,0 +1,2 @@ +Fix two crashes in :mod:`tkinter` and :mod:`socket` modules initialization +under a memory pressure. Sets missing :exc:`MemoryError`. diff --git a/Modules/_tkinter.c b/Modules/_tkinter.c index 137eba40a76..8fa58d07096 100644 --- a/Modules/_tkinter.c +++ b/Modules/_tkinter.c @@ -3574,7 +3574,7 @@ PyInit__tkinter(void) tcl_lock = PyThread_allocate_lock(); if (tcl_lock == NULL) - return NULL; + return PyErr_NoMemory(); m = PyModule_Create(&_tkintermodule); if (m == NULL) diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c index c69a9cc0498..97abd064ffd 100644 --- a/Modules/socketmodule.c +++ b/Modules/socketmodule.c @@ -9288,6 +9288,7 @@ socket_exec(PyObject *m) #if defined(USE_GETHOSTBYNAME_LOCK) netdb_lock = PyThread_allocate_lock(); if (netdb_lock == NULL) { + PyErr_NoMemory(); goto error; } #endif