Close socket in case of errors in setting non-blocking
authorDaniel Gustafsson
Wed, 17 Jan 2024 10:24:11 +0000 (11:24 +0100)
committerDaniel Gustafsson
Wed, 17 Jan 2024 10:24:11 +0000 (11:24 +0100)
If configuring the newly created socket non-blocking fails we
error out and return INVALID_SOCKET, but the socket that had
been created wasn't closed. Fix by issuing closesocket in the
errorpath.

Backpatch to all supported branches.

Author: Ranier Vilela 
Discussion: https://postgr.es/m/CAEudQApmU5CrKefH85VbNYE2y8H=-qqEJbg6RAPU65+vCe+89A@mail.gmail.com
Backpatch-through: v12

src/backend/port/win32/socket.c

index 52944a0d33264c6a588c941af75d5f2449f34ab9..33580011c719c98a4d72ec54ea76f6ce52a9ee51 100644 (file)
@@ -303,6 +303,7 @@ pgwin32_socket(int af, int type, int protocol)
    if (ioctlsocket(s, FIONBIO, &on))
    {
        TranslateSocketError();
+       closesocket(s);
        return INVALID_SOCKET;
    }
    errno = 0;