ctdb-ipalloc: Move if-statement with broken condition
authorMartin Schwenke <martin@meltin.net>
Mon, 23 May 2016 04:41:43 +0000 (14:41 +1000)
committerAmitay Isaacs <amitay@samba.org>
Mon, 4 Jul 2016 13:42:24 +0000 (15:42 +0200)
This pointer is for an array that is always allocated.  The check is
meant to skip a node that has no IP addresses.  However, when there
are no IP addresses the loop below will not do anything anyway.

Add this as a check at the beginning of the function instead.

Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
ctdb/server/ctdb_takeover.c

index cb431b3..e969ab3 100644 (file)
@@ -1240,17 +1240,17 @@ create_merged_ip_list(struct ctdb_context *ctdb, struct ipalloc_state *ipalloc_s
        TALLOC_FREE(ctdb->ip_tree);
        ctdb->ip_tree = trbt_create(ctdb, 0);
 
+       if (ipalloc_state->known_public_ips == NULL) {
+               DEBUG(DEBUG_ERR, ("Known public IPs not set\n"));
+               return NULL;
+       }
+
        for (i=0; i < ctdb->num_nodes; i++) {
 
                if (ctdb->nodes[i]->flags & NODE_FLAGS_DELETED) {
                        continue;
                }
 
-               /* there were no public ips for this node */
-               if (ipalloc_state->known_public_ips == NULL) {
-                       continue;
-               }
-
                public_ips = &ipalloc_state->known_public_ips[i];
 
                for (j=0; j < public_ips->num; j++) {