From: Thomas Kowalski Date: Sat, 30 May 2026 16:25:40 +0000 (+0200) Subject: gh-150406: Check result of PyThread_allocate_lock() for netdb_lock (GH-150407) X-Git-Url: http://git.ipfire.org/gitweb/index.cgi?a=commitdiff_plain;h=1e18c45495185cb547d43c3dd4c1cbdd8482867b;p=thirdparty%2FPython%2Fcpython.git gh-150406: Check result of PyThread_allocate_lock() for netdb_lock (GH-150407) --- 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 000000000000..230e961abd3f --- /dev/null +++ b/Misc/NEWS.d/next/Library/2026-05-25-17-00-00.gh-issue-150406.jF3g63.rst @@ -0,0 +1,3 @@ +Fix a possible crash occurring during :mod:`socket` module initialization +when the system is out of memory on platforms without a reentrant +``gethostbyname``. diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c index 566989d648d2..3eaa8cf75482 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