ctdb-daemon: Drop use of strdup(3) and free(3) when releasing IP
authorMartin Schwenke <martin@meltin.net>
Sat, 20 Aug 2016 10:02:44 +0000 (20:02 +1000)
committerAmitay Isaacs <amitay@samba.org>
Thu, 8 Sep 2016 04:57:20 +0000 (06:57 +0200)
If anything should be used here it should be talloc functions.
However, this is a remnant from when ctdb_sys_find_ifname() was used
here and, for some reason, it used strdup(3).

In this case the interface string doesn't actually need to be copied.
The only use of it is when ctdb_event_script_callback_v() uses it with
the format string in a call to talloc_vasprintf().  In the same
context the IP address isn't copied.

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

index 2955b374f2638370442dc9a8fbcac7b083369b32..f2330d1336094162e02985bde71b1c65b2226b4c 100644 (file)
@@ -928,7 +928,7 @@ int32_t ctdb_control_release_ip(struct ctdb_context *ctdb,
        struct release_ip_callback_state *state;
        struct ctdb_public_ip *pip = (struct ctdb_public_ip *)indata.dptr;
        struct ctdb_vnn *vnn;
-       char *iface;
+       const char *iface;
 
        /* update our vnn list */
        vnn = find_public_ip_vnn(ctdb, &pip->addr);
@@ -985,7 +985,7 @@ int32_t ctdb_control_release_ip(struct ctdb_context *ctdb,
                return -1;
        }
 
-       iface = strdup(ctdb_vnn_iface_string(vnn));
+       iface = ctdb_vnn_iface_string(vnn);
 
        DEBUG(DEBUG_NOTICE,("Release of IP %s/%u on interface %s  node:%d\n",
                ctdb_addr_to_str(&pip->addr),
@@ -997,7 +997,6 @@ int32_t ctdb_control_release_ip(struct ctdb_context *ctdb,
        if (state == NULL) {
                ctdb_set_error(ctdb, "Out of memory at %s:%d",
                               __FILE__, __LINE__);
-               free(iface);
                return -1;
        }
 
@@ -1006,7 +1005,6 @@ int32_t ctdb_control_release_ip(struct ctdb_context *ctdb,
        if (state->addr == NULL) {
                ctdb_set_error(ctdb, "Out of memory at %s:%d",
                               __FILE__, __LINE__);
-               free(iface);
                talloc_free(state);
                return -1;
        }
@@ -1024,7 +1022,6 @@ int32_t ctdb_control_release_ip(struct ctdb_context *ctdb,
                                         iface,
                                         ctdb_addr_to_str(&pip->addr),
                                         vnn->public_netmask_bits);
-       free(iface);
        if (ret != 0) {
                DEBUG(DEBUG_ERR,(__location__ " Failed to release IP %s on interface %s\n",
                        ctdb_addr_to_str(&pip->addr),