commit 344a134bed6113c082e28a73f19e0a0dbff4fa10
Author: Ken Gaillot <kgaillot@redhat.com>
Date:   Thu Oct 27 15:27:53 2016 -0500

    Fix: various: issues discovered via valgrind and coverity
    
    - memory leak in crmd/join_dc.c:do_dc_join_ack()
    - dead code in lib/services/services.c:resources_list_standards()
    - hidden variables in attrd/commands.c:attrd_peer_update(),
      fencing/commands.c:handle_request(), pengine/main.c:pe_ipc_dispatch(),
      lib/cluster/cpg.c:pcmk_message_common_cs(),
      and lib/pengine/utils.c:resource_location()
    - unused value in pengine/native.c:RecurringOp()

diff --git a/attrd/commands.c b/attrd/commands.c
index 94becc9..83502d4 100644
--- a/attrd/commands.c
+++ b/attrd/commands.c
@@ -777,16 +777,17 @@ attrd_peer_update(crm_node_t *peer, xmlNode *xml, const char *host, bool filter)
         }
     }
 
-    /* this only involves cluster nodes. */
-    if(v->nodeid == 0 && (v->is_remote == FALSE)) {
-        if(crm_element_value_int(xml, F_ATTRD_HOST_ID, (int*)&v->nodeid) == 0) {
-            /* Create the name/id association */
-            crm_node_t *peer = crm_get_peer(v->nodeid, host);
-            crm_trace("We know %s's node id now: %s", peer->uname, peer->uuid);
-            if(election_state(writer) == election_won) {
-                write_attributes(FALSE, TRUE);
-                return;
-            }
+    /* If this is a cluster node whose node ID we are learning, remember it */
+    if ((v->nodeid == 0) && (v->is_remote == FALSE)
+        && (crm_element_value_int(xml, F_ATTRD_HOST_ID, (int*)&v->nodeid) == 0)) {
+
+        crm_node_t *known_peer = crm_get_peer(v->nodeid, host);
+
+        crm_trace("We know %s's node id now: %s",
+                  known_peer->uname, known_peer->uuid);
+        if (election_state(writer) == election_won) {
+            write_attributes(FALSE, TRUE);
+            return;
         }
     }
 }
diff --git a/crmd/join_dc.c b/crmd/join_dc.c
index fc2568c..cd63360 100644
--- a/crmd/join_dc.c
+++ b/crmd/join_dc.c
@@ -526,11 +526,12 @@ do_dc_join_ack(long long action,
 
     if (safe_str_eq(join_from, fsa_our_uname)) {
         xmlNode *now_dc_lrmd_state = do_lrm_query(TRUE, fsa_our_uname);
+
         if (now_dc_lrmd_state != NULL) {
             crm_debug("LRM state is updated from do_lrm_query.(%s)", join_from);
             fsa_cib_update(XML_CIB_TAG_STATUS, now_dc_lrmd_state,
                 cib_scope_local | cib_quorum_override | cib_can_create, call_id, NULL);
-            free(now_dc_lrmd_state);
+            free_xml(now_dc_lrmd_state);
         } else {
             crm_warn("Could not get our LRM state. LRM state is updated from join_ack->xml.(%s)", join_from);
             fsa_cib_update(XML_CIB_TAG_STATUS, join_ack->xml,
diff --git a/fencing/commands.c b/fencing/commands.c
index 00bf320..a4699ee 100644
--- a/fencing/commands.c
+++ b/fencing/commands.c
@@ -2461,30 +2461,30 @@ handle_request(crm_client_t * client, uint32_t id, uint32_t flags, xmlNode * req
         rc = stonith_fence_history(request, &data);
 
     } else if (crm_str_eq(op, STONITH_OP_DEVICE_ADD, TRUE)) {
-        const char *id = NULL;
+        const char *device_id = NULL;
 
-        rc = stonith_device_register(request, &id, FALSE);
-        do_stonith_notify_device(call_options, op, rc, id);
+        rc = stonith_device_register(request, &device_id, FALSE);
+        do_stonith_notify_device(call_options, op, rc, device_id);
 
     } else if (crm_str_eq(op, STONITH_OP_DEVICE_DEL, TRUE)) {
         xmlNode *dev = get_xpath_object("//" F_STONITH_DEVICE, request, LOG_ERR);
-        const char *id = crm_element_value(dev, XML_ATTR_ID);
+        const char *device_id = crm_element_value(dev, XML_ATTR_ID);
 
-        rc = stonith_device_remove(id, FALSE);
-        do_stonith_notify_device(call_options, op, rc, id);
+        rc = stonith_device_remove(device_id, FALSE);
+        do_stonith_notify_device(call_options, op, rc, device_id);
 
     } else if (crm_str_eq(op, STONITH_OP_LEVEL_ADD, TRUE)) {
-        char *id = NULL;
+        char *device_id = NULL;
 
-        rc = stonith_level_register(request, &id);
-        do_stonith_notify_level(call_options, op, rc, id);
-        free(id);
+        rc = stonith_level_register(request, &device_id);
+        do_stonith_notify_level(call_options, op, rc, device_id);
+        free(device_id);
 
     } else if (crm_str_eq(op, STONITH_OP_LEVEL_DEL, TRUE)) {
-        char *id = NULL;
+        char *device_id = NULL;
 
-        rc = stonith_level_remove(request, &id);
-        do_stonith_notify_level(call_options, op, rc, id);
+        rc = stonith_level_remove(request, &device_id);
+        do_stonith_notify_level(call_options, op, rc, device_id);
 
     } else if (crm_str_eq(op, STONITH_OP_CONFIRM, TRUE)) {
         async_command_t *cmd = create_async_command(request);
@@ -2498,12 +2498,12 @@ handle_request(crm_client_t * client, uint32_t id, uint32_t flags, xmlNode * req
         free_xml(reply);
 
     } else if(safe_str_eq(op, CRM_OP_RM_NODE_CACHE)) {
-        int id = 0;
+        int node_id = 0;
         const char *name = NULL;
 
-        crm_element_value_int(request, XML_ATTR_ID, &id);
+        crm_element_value_int(request, XML_ATTR_ID, &node_id);
         name = crm_element_value(request, XML_ATTR_UNAME);
-        reap_crm_member(id, name);
+        reap_crm_member(node_id, name);
 
         return pcmk_ok;
 
diff --git a/lib/cluster/cpg.c b/lib/cluster/cpg.c
index 00a8c18..5efafc8 100644
--- a/lib/cluster/cpg.c
+++ b/lib/cluster/cpg.c
@@ -315,8 +315,7 @@ pcmk_message_common_cs(cpg_handle_t handle, uint32_t nodeid, uint32_t pid, void
         goto badmsg;
 
     } else if (safe_str_eq("identify", data)) {
-        int pid = getpid();
-        char *pid_s = crm_itoa(pid);
+        char *pid_s = crm_itoa((int) getpid());
 
         send_cluster_text(crm_class_cluster, pid_s, TRUE, NULL, crm_msg_ais);
         free(pid_s);
diff --git a/lib/pengine/utils.c b/lib/pengine/utils.c
index b92cf53..2e43623 100644
--- a/lib/pengine/utils.c
+++ b/lib/pengine/utils.c
@@ -1294,18 +1294,18 @@ resource_location(resource_t * rsc, node_t * node, int score, const char *tag,
         GListPtr gIter = data_set->nodes;
 
         for (; gIter != NULL; gIter = gIter->next) {
-            node_t *node = (node_t *) gIter->data;
+            node_t *node_iter = (node_t *) gIter->data;
 
-            resource_node_score(rsc, node, score, tag);
+            resource_node_score(rsc, node_iter, score, tag);
         }
 
     } else {
         GHashTableIter iter;
-        node_t *node = NULL;
+        node_t *node_iter = NULL;
 
         g_hash_table_iter_init(&iter, rsc->allowed_nodes);
-        while (g_hash_table_iter_next(&iter, NULL, (void **)&node)) {
-            resource_node_score(rsc, node, score, tag);
+        while (g_hash_table_iter_next(&iter, NULL, (void **)&node_iter)) {
+            resource_node_score(rsc, node_iter, score, tag);
         }
     }
 
diff --git a/lib/services/services.c b/lib/services/services.c
index a6b776a..a3c99a6 100644
--- a/lib/services/services.c
+++ b/lib/services/services.c
@@ -763,24 +763,20 @@ resources_list_standards(void)
 
 #if SUPPORT_SYSTEMD
     agents = systemd_unit_listall();
-#else
-    agents = NULL;
-#endif
-
     if (agents) {
         standards = g_list_append(standards, strdup("systemd"));
         g_list_free_full(agents, free);
     }
-#if SUPPORT_UPSTART
-    agents = upstart_job_listall();
-#else
-    agents = NULL;
 #endif
 
+#if SUPPORT_UPSTART
+    agents = upstart_job_listall();
     if (agents) {
         standards = g_list_append(standards, strdup("upstart"));
         g_list_free_full(agents, free);
     }
+#endif
+
 #if SUPPORT_NAGIOS
     agents = resources_os_list_nagios_agents();
     if (agents) {
diff --git a/pengine/main.c b/pengine/main.c
index 8bdcea7..01d4eb6 100644
--- a/pengine/main.c
+++ b/pengine/main.c
@@ -71,9 +71,9 @@ pe_ipc_dispatch(qb_ipcs_connection_t * qbc, void *data, size_t size)
 
     crm_ipcs_send_ack(c, id, flags, "ack", __FUNCTION__, __LINE__);
     if (msg != NULL) {
-        xmlNode *data = get_message_xml(msg, F_CRM_DATA);
+        xmlNode *data_xml = get_message_xml(msg, F_CRM_DATA);
 
-        process_pe_message(msg, data, c);
+        process_pe_message(msg, data_xml, c);
         free_xml(msg);
     }
     return 0;
diff --git a/pengine/native.c b/pengine/native.c
index 9c27aed..b24e3fd 100644
--- a/pengine/native.c
+++ b/pengine/native.c
@@ -737,7 +737,6 @@ RecurringOp(resource_t * rsc, action_t * start, node_t * node,
                    role2text(rsc->next_role));
 
         free(key);
-        key = NULL;
         return;
     }
 
