https://github.com/python/cpython/commit/4d91835af5a9e7fe47609f7ec9457f6e8af39d12
commit: 4d91835af5a9e7fe47609f7ec9457f6e8af39d12
branch: 3.13
author: Miss Islington (bot) <[email protected]>
committer: serhiy-storchaka <[email protected]>
date: 2026-05-30T19:56:46+03:00
summary:

[3.13] gh-150406: Check result of PyThread_allocate_lock() for netdb_lock 
(GH-150407) (GH-150618)

(cherry picked from commit 1e18c45495185cb547d43c3dd4c1cbdd8482867b)

Co-authored-by: Thomas Kowalski <[email protected]>

files:
A Misc/NEWS.d/next/Library/2026-05-25-17-00-00.gh-issue-150406.jF3g63.rst
M Modules/socketmodule.c

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 000000000000000..230e961abd3f588
--- /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 becdf9af7181ec0..9cdf207e7a3380d 100644
--- a/Modules/socketmodule.c
+++ b/Modules/socketmodule.c
@@ -8939,6 +8939,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

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]

Reply via email to