Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0848146

Browse files
committed
Don't close an already closed socket.
1 parent 9b05811 commit 0848146

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

Modules/socketmodule.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -610,9 +610,11 @@ BUILD_FUNC_DEF_2(PySocketSock_close,PySocketSockObject *,s, PyObject *,args)
610610
{
611611
if (!PyArg_NoArgs(args))
612612
return NULL;
613-
Py_BEGIN_ALLOW_THREADS
614-
(void) close(s->sock_fd);
615-
Py_END_ALLOW_THREADS
613+
if (s->sock_fd != -1) {
614+
Py_BEGIN_ALLOW_THREADS
615+
(void) close(s->sock_fd);
616+
Py_END_ALLOW_THREADS
617+
}
616618
s->sock_fd = -1;
617619
Py_INCREF(Py_None);
618620
return Py_None;

0 commit comments

Comments
 (0)