Back porting coverity issues fix patch from master branch.
authorMuhammad Usama <m.usama@gmail.com>
Tue, 5 Aug 2014 14:47:31 +0000 (19:47 +0500)
committerMuhammad Usama <m.usama@gmail.com>
Tue, 5 Aug 2014 14:47:31 +0000 (19:47 +0500)
Fix coverity issue:1111377 Unchecked return value
Fix coverity issue:1111381 Logically dead code
Fix coverity issue:1222992 Unchecked return value
Fix coverity issue:1222993 Unchecked return value

child.c
main.c
pool_auth.c
pool_session_context.c

diff --git a/child.c b/child.c
index c7b15abb11cf228a5d5baec861c1aa323ec27807..49b08747a1b2da4bd28056ef2253df33bc83c9f0 100644 (file)
--- a/child.c
+++ b/child.c
@@ -2062,8 +2062,9 @@ static void init_system_db_connection(void)
 {      
        if (pool_config->parallel_mode || pool_config->enable_query_cache)
        {
-               system_db_connect();
-               if (PQstatus(system_db_info->pgconn) != CONNECTION_OK)
+               int nRet;
+               nRet = system_db_connect();
+               if (nRet || PQstatus(system_db_info->pgconn) != CONNECTION_OK)
                {
                        pool_error("Could not make persistent libpq system DB connection");
                }
diff --git a/main.c b/main.c
index 31fa32e8b22ebd7861e85952bc078ad15aef6317..02948506df1d8968017f903bb7d847d6b5389c2c 100644 (file)
--- a/main.c
+++ b/main.c
@@ -2572,7 +2572,6 @@ static int find_primary_node(void)
        BackendInfo *bkinfo;
        POOL_CONNECTION_POOL_SLOT *s;
        POOL_CONNECTION *con; 
-       POOL_STATUS status;
        POOL_SELECT_RESULT *res;
        bool is_standby;
        int i;
@@ -2640,25 +2639,31 @@ static int find_primary_node(void)
                        return -1;
                }
 #endif
-               status = do_query(con, "SELECT pg_is_in_recovery()",
-                                                 &res, PROTO_MAJOR_V3);
-               if (res->numrows <= 0)
-               {
-                       pool_log("find_primary_node: do_query returns no rows");
-               }
-               if (res->data[0] == NULL)
+               if(do_query(con, "SELECT pg_is_in_recovery()", &res, PROTO_MAJOR_V3) == POOL_CONTINUE)
                {
-                       pool_log("find_primary_node: do_query returns no data");
+                       if (res->numrows <= 0)
+                       {
+                               pool_log("find_primary_node: do_query returns no rows");
+                       }
+                       if (res->data[0] == NULL)
+                       {
+                               pool_log("find_primary_node: do_query returns no data");
+                       }
+                       if (res->nullflags[0] == -1)
+                       {
+                               pool_log("find_primary_node: do_query returns NULL");
+                       }
+                       if (res->data[0] && !strcmp(res->data[0], "t"))
+                       {
+                               is_standby = true;
+                       }
                }
-               if (res->nullflags[0] == -1)
+               else
                {
-                       pool_log("find_primary_node: do_query returns NULL");
+                       pool_log("find_primary_node: do_query failed");
                }
-               if (res->data[0] && !strcmp(res->data[0], "t"))
-               {
-                       is_standby = true;
-               }   
-               free_select_result(res);
+               if(res)
+                       free_select_result(res);
                discard_persistent_db_connection(s);
 
                /*
index 811fa6cbe73220c8fc1cb8cfe618f1b53ac74566..387a98719a623d62ec8406f49fad84abf50b8001 100644 (file)
@@ -330,12 +330,6 @@ from pool_read_message_length and recheck the pg_hba.conf settings.");
         */
        if (protoMajor == PROTO_MAJOR_V3)
        {
-               if (kind != 'K')
-               {
-                       pool_error("pool_do_auth: expect \"K\" got %c", kind);
-                       return -1;
-               }
-
                if ((length = pool_read_message_length(cp)) != 12)
                {
                        pool_error("pool_do_auth: invalid messages length(%d) for BackendKeyData", length);
index d32b66e8892ae7794751fc21e7927c2422fd6fd5..5fa1581ae37add35fd6d777c0a8596d2361ce2e6 100644 (file)
@@ -729,6 +729,13 @@ POOL_TRANSACTION_ISOLATION pool_get_transaction_isolation(void)
        /* No cached data is available. Ask backend. */
        status = do_query(MASTER(session_context->backend),
                                          "SELECT current_setting('transaction_isolation')", &res, MAJOR(session_context->backend));
+       if(status != POOL_CONTINUE)
+       {
+               pool_error("pool_get_transaction_isolation: do_query returns no rows");
+               if(res)
+                       free_select_result(res);
+               return POOL_UNKNOWN;
+       }
 
        if (res->numrows <= 0)
        {
@@ -764,7 +771,8 @@ POOL_TRANSACTION_ISOLATION pool_get_transaction_isolation(void)
                ret = POOL_UNKNOWN;
        }   
 
-       free_select_result(res);
+       if(res)
+               free_select_result(res);
 
        if (ret != POOL_UNKNOWN)
                session_context->transaction_isolation = ret;