]> granicus.if.org Git - python/commitdiff
Adapted from a patch by Barry Scott, SF patch #102875 and SF bug
authorGuido van Rossum <guido@python.org>
Mon, 18 Dec 2000 22:23:44 +0000 (22:23 +0000)
committerGuido van Rossum <guido@python.org>
Mon, 18 Dec 2000 22:23:44 +0000 (22:23 +0000)
#125981: closing sockets was not thread-safe.

Modules/socketmodule.c

index e9b3aadfecf87aa5fc139ddfd67930db86ee3ccb..11e87bc5ec9d344bb53fafd238cd7729039a0d1c 100644 (file)
@@ -904,14 +904,15 @@ pair (host, port); the host must refer to the local host.";
 static PyObject *
 PySocketSock_close(PySocketSockObject *s, PyObject *args)
 {
+       SOCKET_T fd;
        if (!PyArg_ParseTuple(args, ":close"))
                return NULL;
-       if (s->sock_fd != -1) {
+       if ((fd = s->sock_fd) != -1) {
+               s->sock_fd = -1;
                Py_BEGIN_ALLOW_THREADS
-               (void) SOCKETCLOSE(s->sock_fd);
+               (void) SOCKETCLOSE(fd);
                Py_END_ALLOW_THREADS
        }
-       s->sock_fd = -1;
        Py_INCREF(Py_None);
        return Py_None;
 }