Fix for Coverity warnings in watchdog and lifecheck
authorMuhammad Usama <m.usama@gmail.com>
Thu, 3 Oct 2019 14:53:44 +0000 (19:53 +0500)
committerMuhammad Usama <m.usama@gmail.com>
Thu, 3 Oct 2019 14:53:44 +0000 (19:53 +0500)
src/watchdog/watchdog.c
src/watchdog/wd_lifecheck.c

index 0a0e81ef67e65080147f91a4964f3869be8579ca..c240717da3c5d00db7b46ad9e13ba84ff67c9c3a 100644 (file)
@@ -2784,7 +2784,14 @@ static IPC_CMD_PREOCESS_RES process_IPC_failover_indication(WDCommandData * ipcC
 
                        if (root && root->type == json_object)
                        {
-                               json_get_int_value_for_key(root, "FailoverFuncState", &failoverState);
+                               if (json_get_int_value_for_key(root, "FailoverFuncState", &failoverState))
+                               {
+                                       ereport(LOG,
+                                                       (errmsg("unable to process failover indication"),
+                                                        errdetail("failed to get failover state from json data in command packet")));
+                                       res = FAILOVER_RES_INVALID_FUNCTION;
+                               }
+
                        }
                        else
                        {
@@ -4221,6 +4228,8 @@ node_lost_while_ipc_command(WatchdogNode * wdNode)
 
                cleanUpIPCCommand(ipcCommand);
        }
+
+       list_free(ipcCommands_to_del);
 }
 
 
@@ -4313,6 +4322,8 @@ service_internal_command(void)
                g_cluster.clusterCommands = list_delete_ptr(g_cluster.clusterCommands, clusterCommand);
                MemoryContextDelete(clusterCommand->memoryContext);
        }
+
+       list_free(finishedCommands);
 }
 
 /* remove the unreachable nodes from cluster */
@@ -4470,6 +4481,8 @@ check_for_current_command_timeout(void)
                g_cluster.clusterCommands = list_delete_ptr(g_cluster.clusterCommands, clusterCommand);
                MemoryContextDelete(clusterCommand->memoryContext);
        }
+
+       list_free(finishedCommands);
 }
 
 
@@ -4553,6 +4566,9 @@ issue_watchdog_internal_command(WatchdogNode * wdNode, WDPacketData * pkt, int t
                if (nodeResult == NULL)
                {
                        /* should never hapen */
+                       ereport(WARNING,
+                                       (errmsg("Internal error. Not able to locate node result slot")));
+                       MemoryContextDelete(clusterCommand->memoryContext);
                        return -1;
                }
                if (send_message_to_node(nodeResult->wdNode, pkt) == false)
@@ -5015,6 +5031,9 @@ watchdog_state_machine(WD_EVENTS event, WatchdogNode * wdNode, WDPacketData * pk
                                ereport(DEBUG1,
                                                (errmsg("IP = %s", ip ? ip : "NULL")));
                        }
+
+                       list_free_deep(local_addresses);
+                       local_addresses = NULL;
                }
        }
 
@@ -5657,9 +5676,9 @@ watchdog_state_machine_coordinator(WD_EVENTS event, WatchdogNode * wdNode, WDPac
                                                         */
                                                        wd_IP_up();
                                                }
-                                               list_free_deep(local_addresses);
-                                               local_addresses = NULL;
                                        }
+                                       list_free_deep(local_addresses);
+                                       local_addresses = NULL;
                                }
                        }
                        break;
@@ -6760,6 +6779,8 @@ process_wd_func_commands_for_timer_events(void)
        {
                g_cluster.wd_timer_commands = list_delete_ptr(g_cluster.wd_timer_commands, lfirst(lc));
        }
+
+       list_free(timers_to_del);
 }
 
 static void
index 75d2e835df81839dce967fe3f27eb3a6a822a9a8..15e5667c5cf2515c650960f8d78982e6810bb6a5 100644 (file)
@@ -827,6 +827,13 @@ check_pgpool_status_by_query(void)
                thread_arg[i].lifeCheckNode = node;
                thread_arg[i].password = password;
                rc = watchdog_thread_create(&thread[i], &attr, thread_ping_pgpool, (void *) &thread_arg[i]);
+               if (rc)
+               {
+                       ereport(WARNING,
+                                       (errmsg("failed to create thread for checking pgpool status by query for  %d (%s:%d)",
+                                                       i, node->hostName, node->pgpoolPort),
+                                        errdetail("pthread_create failed with error code %d: %s",rc, strerror(rc))));
+               }
        }
 
        pthread_attr_destroy(&attr);