summaryrefslogtreecommitdiff
path: root/src/interfaces/libpq/fe-connect.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/interfaces/libpq/fe-connect.c')
-rw-r--r--src/interfaces/libpq/fe-connect.c31
1 files changed, 17 insertions, 14 deletions
diff --git a/src/interfaces/libpq/fe-connect.c b/src/interfaces/libpq/fe-connect.c
index 7b9e53cd7de..1552eabe1e9 100644
--- a/src/interfaces/libpq/fe-connect.c
+++ b/src/interfaces/libpq/fe-connect.c
@@ -2911,23 +2911,30 @@ makeEmptyPGconn(void)
#ifdef WIN32
/*
- * Make sure socket support is up and running.
+ * Make sure socket support is up and running in this process.
+ *
+ * Note: the Windows documentation says that we should eventually do a
+ * matching WSACleanup() call, but experience suggests that that is at
+ * least as likely to cause problems as fix them. So we don't.
*/
- WSADATA wsaData;
+ static bool wsastartup_done = false;
- if (WSAStartup(MAKEWORD(1, 1), &wsaData))
- return NULL;
+ if (!wsastartup_done)
+ {
+ WSADATA wsaData;
+
+ if (WSAStartup(MAKEWORD(1, 1), &wsaData) != 0)
+ return NULL;
+ wsastartup_done = true;
+ }
+
+ /* Forget any earlier error */
WSASetLastError(0);
-#endif
+#endif /* WIN32 */
conn = (PGconn *) malloc(sizeof(PGconn));
if (conn == NULL)
- {
-#ifdef WIN32
- WSACleanup();
-#endif
return conn;
- }
/* Zero all pointers and booleans */
MemSet(conn, 0, sizeof(PGconn));
@@ -3077,10 +3084,6 @@ freePGconn(PGconn *conn)
termPQExpBuffer(&conn->workBuffer);
free(conn);
-
-#ifdef WIN32
- WSACleanup();
-#endif
}
/*