diff --git a/Misc/NEWS.d/next/Library/2026-05-25-17-00-00.gh-issue-150406.jF3g63.rst b/Misc/NEWS.d/next/Library/2026-05-25-17-00-00.gh-issue-150406.jF3g63.rst new file mode 100644 index 00000000000000..df9cd1b716ccf8 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2026-05-25-17-00-00.gh-issue-150406.jF3g63.rst @@ -0,0 +1 @@ +Fix a possible crash in the :mod:`socket` module initialization. diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c index 566989d648d2f7..3eaa8cf7548239 100644 --- a/Modules/socketmodule.c +++ b/Modules/socketmodule.c @@ -9293,6 +9293,9 @@ socket_exec(PyObject *m) /* Initialize gethostbyname lock */ #if defined(USE_GETHOSTBYNAME_LOCK) netdb_lock = PyThread_allocate_lock(); + if (netdb_lock == NULL) { + goto error; + } #endif #ifdef MS_WINDOWS