Don't dump core if pq_comm_reset() is called before pq_init().
authorRobert Haas <rhaas@postgresql.org>
Fri, 5 Dec 2014 00:47:06 +0000 (19:47 -0500)
committerRobert Haas <rhaas@postgresql.org>
Fri, 5 Dec 2014 00:49:43 +0000 (19:49 -0500)
This can happen if an error occurs in a standalone backend.  This bug
was introduced by commit 2bd9e412f92bc6a68f3e8bcb18e04955cc35001d.

Reported by Álvaro Herrera.

src/backend/libpq/pqcomm.c

index 74161970ab51362c46c9f2303343ded8e57d9ab9..a4abf3ab8320337445e3bd085a93a9df4430235e 100644 (file)
@@ -105,9 +105,6 @@ char       *Unix_socket_group;
 /* Where the Unix socket files are (list of palloc'd strings) */
 static List *sock_paths = NIL;
 
-PQcommMethods *PqCommMethods;
-
-
 /*
  * Buffers for low-level I/O.
  *
@@ -154,8 +151,6 @@ static int  Lock_AF_UNIX(char *unixSocketDir, char *unixSocketPath);
 static int Setup_AF_UNIX(char *sock_path);
 #endif   /* HAVE_UNIX_SOCKETS */
 
-PQcommMethods PQcommSocketMethods;
-
 static PQcommMethods PqCommSocketMethods = {
    socket_comm_reset,
    socket_flush,
@@ -167,6 +162,9 @@ static PQcommMethods PqCommSocketMethods = {
    socket_endcopyout
 };
 
+PQcommMethods *PqCommMethods = &PqCommSocketMethods;
+
+
 
 /* --------------------------------
  *     pq_init - initialize libpq at backend startup
@@ -175,7 +173,6 @@ static PQcommMethods PqCommSocketMethods = {
 void
 pq_init(void)
 {
-   PqCommMethods = &PqCommSocketMethods;
    PqSendBufferSize = PQ_SEND_BUFFER_SIZE;
    PqSendBuffer = MemoryContextAlloc(TopMemoryContext, PqSendBufferSize);
    PqSendPointer = PqSendStart = PqRecvPointer = PqRecvLength = 0;