rework GetPoolManagerHandle a bit to get rid of compiler warnings
authorTomas Vondra <[email protected]>
Tue, 23 Aug 2016 13:43:04 +0000 (15:43 +0200)
committerPavan Deolasee <[email protected]>
Fri, 26 Aug 2016 12:14:04 +0000 (17:44 +0530)
Under rare conditions (missing support for unix sockets or empty
Unix_socket_directories) the fdsocket variable remained unitialized.
Handle this case explicitly, and also fix a few minor annoyances
(remove extra braces around a single-line block).

src/backend/pgxc/pool/poolmgr.c

index f86bd31bd8edefbf312c6fe3deae8a69859727f0..e3fe8ea906b746c3c57f782d4f9acefc55561b68 100644 (file)
@@ -341,7 +341,7 @@ static void
 GetPoolManagerHandle(void)
 {
        PoolHandle *handle;
-       int                     fdsock;
+       int                     fdsock = -1;
 
        if (poolHandle)
                /* already connected */
@@ -398,8 +398,19 @@ GetPoolManagerHandle(void)
        }
 #endif
 
-       /* Allocate handle */
        /*
+        * Actual connection errors should be reported by the block above,
+        * but perhaps we haven't actually executed it - either because
+        * the Unix_socket_directories is not set, or because there's no
+        * support for UNIX_SOCKETS. Just bail out in that case.
+        */
+       if (fdsock < 0)
+               ereport(ERROR,
+                               (errmsg("failed to connect to pool manager: %m")));
+
+       /*
+        * Allocate handle
+        *
         * XXX we may change malloc here to palloc but first ensure
         * the CurrentMemoryContext is properly set.
         * The handle allocated just before new session is forked off and
@@ -408,11 +419,9 @@ GetPoolManagerHandle(void)
         */
        handle = (PoolHandle *) malloc(sizeof(PoolHandle));
        if (!handle)
-       {
                ereport(ERROR,
                                (errcode(ERRCODE_OUT_OF_MEMORY),
                                 errmsg("out of memory")));
-       }
 
        handle->port.fdsock = fdsock;
        handle->port.RecvLength = 0;