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 000000000000000..2e51fd45b595486 --- /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 38b0b101c9b935c..ee717f723d5bf3b 100644 --- a/Modules/_tkinter.c +++ b/Modules/_tkinter.c @@ -3470,7 +3470,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 9abd94b9b905ea5..8008c101251c660 100644 --- a/Modules/socketmodule.c +++ b/Modules/socketmodule.c @@ -8942,6 +8942,7 @@ socket_exec(PyObject *m) #if defined(USE_GETHOSTBYNAME_LOCK) netdb_lock = PyThread_allocate_lock(); if (netdb_lock == NULL) { + PyErr_NoMemory(); goto error; } #endif