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()

Index: pacemaker/attrd/commands.c
===================================================================
--- pacemaker.orig/attrd/commands.c
+++ pacemaker/attrd/commands.c
@@ -734,16 +734,17 @@ attrd_peer_update(crm_node_t *peer, xmlN
         }
     }
 
-    /* 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;
         }
     }
 }
Index: pacemaker/crmd/join_dc.c
===================================================================
--- pacemaker.orig/crmd/join_dc.c
+++ pacemaker/crmd/join_dc.c
@@ -523,11 +523,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,
Index: pacemaker/fencing/commands.c
===================================================================
--- pacemaker.orig/fencing/commands.c
+++ pacemaker/fencing/commands.c
@@ -2462,12 +2462,12 @@ handle_request(crm_client_t * client, ui
         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;
         xmlNode *notify_data = create_xml_node(NULL, op);
 
-        rc = stonith_device_register(request, &id, FALSE);
+        rc = stonith_device_register(request, &device_id, FALSE);
 
-        crm_xml_add(notify_data, F_STONITH_DEVICE, id);
+        crm_xml_add(notify_data, F_STONITH_DEVICE, device_id);
         crm_xml_add_int(notify_data, F_STONITH_ACTIVE, g_hash_table_size(device_list));
 
         do_stonith_notify(call_options, op, rc, notify_data);
@@ -2475,37 +2475,37 @@ handle_request(crm_client_t * client, ui
 
     } 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);
         xmlNode *notify_data = create_xml_node(NULL, op);
 
-        rc = stonith_device_remove(id, FALSE);
+        rc = stonith_device_remove(device_id, FALSE);
 
-        crm_xml_add(notify_data, F_STONITH_DEVICE, id);
+        crm_xml_add(notify_data, F_STONITH_DEVICE, device_id);
         crm_xml_add_int(notify_data, F_STONITH_ACTIVE, g_hash_table_size(device_list));
 
         do_stonith_notify(call_options, op, rc, notify_data);
         free_xml(notify_data);
 
     } else if (crm_str_eq(op, STONITH_OP_LEVEL_ADD, TRUE)) {
-        char *id = NULL;
+        char *device_id = NULL;
         xmlNode *notify_data = create_xml_node(NULL, op);
 
-        rc = stonith_level_register(request, &id);
+        rc = stonith_level_register(request, &device_id);
 
-        crm_xml_add(notify_data, F_STONITH_DEVICE, id);
+        crm_xml_add(notify_data, F_STONITH_DEVICE, device_id);
         crm_xml_add_int(notify_data, F_STONITH_ACTIVE, g_hash_table_size(topology));
 
         do_stonith_notify(call_options, op, rc, notify_data);
         free_xml(notify_data);
-        free(id);
+        free(device_id);
 
     } else if (crm_str_eq(op, STONITH_OP_LEVEL_DEL, TRUE)) {
-        char *id = NULL;
+        char *device_id = NULL;
         xmlNode *notify_data = create_xml_node(NULL, op);
 
-        rc = stonith_level_remove(request, &id);
+        rc = stonith_level_remove(request, &device_id);
 
-        crm_xml_add(notify_data, F_STONITH_DEVICE, id);
+        crm_xml_add(notify_data, F_STONITH_DEVICE, device_id);
         crm_xml_add_int(notify_data, F_STONITH_ACTIVE, g_hash_table_size(topology));
 
         do_stonith_notify(call_options, op, rc, notify_data);
@@ -2523,12 +2523,12 @@ handle_request(crm_client_t * client, ui
         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;
 
Index: pacemaker/lib/cluster/cpg.c
===================================================================
--- pacemaker.orig/lib/cluster/cpg.c
+++ pacemaker/lib/cluster/cpg.c
@@ -315,8 +315,7 @@ pcmk_message_common_cs(cpg_handle_t hand
         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);
Index: pacemaker/lib/pengine/utils.c
===================================================================
--- pacemaker.orig/lib/pengine/utils.c
+++ pacemaker/lib/pengine/utils.c
@@ -1290,18 +1290,18 @@ resource_location(resource_t * rsc, node
         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);
         }
     }
 
Index: pacemaker/lib/services/services.c
===================================================================
--- pacemaker.orig/lib/services/services.c
+++ pacemaker/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) {
Index: pacemaker/pengine/main.c
===================================================================
--- pacemaker.orig/pengine/main.c
+++ pacemaker/pengine/main.c
@@ -71,9 +71,9 @@ pe_ipc_dispatch(qb_ipcs_connection_t * q
 
     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;
Index: pacemaker/pengine/native.c
===================================================================
--- pacemaker.orig/pengine/native.c
+++ pacemaker/pengine/native.c
@@ -737,7 +737,6 @@ RecurringOp(resource_t * rsc, action_t *
                    role2text(rsc->next_role));
 
         free(key);
-        key = NULL;
         return;
     }
 
