network: use g_strdup instead of VIR_STRDUP

Replace all occurrences of
  if (VIR_STRDUP(a, b) < 0)
     /* effectively dead code */
with:
  a = g_strdup(b);

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Ján Tomko 2019-10-20 13:49:46 +02:00
parent 380bc1bec7
commit 4d81b800e2
2 changed files with 18 additions and 37 deletions

View File

@ -739,19 +739,12 @@ networkStateInitialize(bool privileged,
* /etc/libvirt/... && /var/(run|lib)/libvirt/... (system/privileged). * /etc/libvirt/... && /var/(run|lib)/libvirt/... (system/privileged).
*/ */
if (privileged) { if (privileged) {
if (VIR_STRDUP(network_driver->networkConfigDir, network_driver->networkConfigDir = g_strdup(SYSCONFDIR "/libvirt/qemu/networks");
SYSCONFDIR "/libvirt/qemu/networks") < 0 || network_driver->networkAutostartDir = g_strdup(SYSCONFDIR "/libvirt/qemu/networks/autostart");
VIR_STRDUP(network_driver->networkAutostartDir, network_driver->stateDir = g_strdup(RUNSTATEDIR "/libvirt/network");
SYSCONFDIR "/libvirt/qemu/networks/autostart") < 0 || network_driver->pidDir = g_strdup(RUNSTATEDIR "/libvirt/network");
VIR_STRDUP(network_driver->stateDir, network_driver->dnsmasqStateDir = g_strdup(LOCALSTATEDIR "/lib/libvirt/dnsmasq");
RUNSTATEDIR "/libvirt/network") < 0 || network_driver->radvdStateDir = g_strdup(LOCALSTATEDIR "/lib/libvirt/radvd");
VIR_STRDUP(network_driver->pidDir,
RUNSTATEDIR "/libvirt/network") < 0 ||
VIR_STRDUP(network_driver->dnsmasqStateDir,
LOCALSTATEDIR "/lib/libvirt/dnsmasq") < 0 ||
VIR_STRDUP(network_driver->radvdStateDir,
LOCALSTATEDIR "/lib/libvirt/radvd") < 0)
goto error;
} else { } else {
configdir = virGetUserConfigDirectory(); configdir = virGetUserConfigDirectory();
rundir = virGetUserRuntimeDirectory(); rundir = virGetUserRuntimeDirectory();
@ -2817,8 +2810,7 @@ networkCreateInterfacePool(virNetworkDefPtr netdef)
case VIR_NETWORK_FORWARD_VEPA: case VIR_NETWORK_FORWARD_VEPA:
case VIR_NETWORK_FORWARD_PASSTHROUGH: case VIR_NETWORK_FORWARD_PASSTHROUGH:
if (thisName) { if (thisName) {
if (VIR_STRDUP(thisIf->device.dev, thisName) < 0) thisIf->device.dev = g_strdup(thisName);
goto cleanup;
thisIf->type = VIR_NETWORK_FORWARD_HOSTDEV_DEVICE_NETDEV; thisIf->type = VIR_NETWORK_FORWARD_HOSTDEV_DEVICE_NETDEV;
netdef->forward.nifs++; netdef->forward.nifs++;
} else { } else {
@ -4437,19 +4429,14 @@ networkGetDHCPLeases(virNetworkPtr net,
} }
} }
if ((VIR_STRDUP(lease->mac, mac_tmp) < 0) || lease->mac = g_strdup(mac_tmp);
(VIR_STRDUP(lease->ipaddr, ip_tmp) < 0) || lease->ipaddr = g_strdup(ip_tmp);
(VIR_STRDUP(lease->iface, def->bridge) < 0)) lease->iface = g_strdup(def->bridge);
goto error;
/* Fields that can be NULL */ /* Fields that can be NULL */
if ((VIR_STRDUP(lease->iaid, lease->iaid = g_strdup(virJSONValueObjectGetString(lease_tmp, "iaid"));
virJSONValueObjectGetString(lease_tmp, "iaid")) < 0) || lease->clientid = g_strdup(virJSONValueObjectGetString(lease_tmp, "client-id"));
(VIR_STRDUP(lease->clientid, lease->hostname = g_strdup(virJSONValueObjectGetString(lease_tmp, "hostname"));
virJSONValueObjectGetString(lease_tmp, "client-id")) < 0) ||
(VIR_STRDUP(lease->hostname,
virJSONValueObjectGetString(lease_tmp, "hostname")) < 0))
goto error;
if (VIR_INSERT_ELEMENT(leases_ret, nleases, nleases, lease) < 0) if (VIR_INSERT_ELEMENT(leases_ret, nleases, nleases, lease) < 0)
goto error; goto error;
@ -4622,8 +4609,7 @@ networkAllocatePort(virNetworkObjPtr obj,
*/ */
port->plugtype = VIR_NETWORK_PORT_PLUG_TYPE_NETWORK; port->plugtype = VIR_NETWORK_PORT_PLUG_TYPE_NETWORK;
if (VIR_STRDUP(port->plug.bridge.brname, netdef->bridge) < 0) port->plug.bridge.brname = g_strdup(netdef->bridge);
goto cleanup;
port->plug.bridge.macTableManager = netdef->macTableManager; port->plug.bridge.macTableManager = netdef->macTableManager;
if (port->virtPortProfile) { if (port->virtPortProfile) {
@ -4686,8 +4672,7 @@ networkAllocatePort(virNetworkObjPtr obj,
*/ */
port->plugtype = VIR_NETWORK_PORT_PLUG_TYPE_BRIDGE; port->plugtype = VIR_NETWORK_PORT_PLUG_TYPE_BRIDGE;
if (VIR_STRDUP(port->plug.bridge.brname, netdef->bridge) < 0) port->plug.bridge.brname = g_strdup(netdef->bridge);
goto cleanup;
port->plug.bridge.macTableManager = netdef->macTableManager; port->plug.bridge.macTableManager = netdef->macTableManager;
if (port->virtPortProfile) { if (port->virtPortProfile) {
@ -4791,9 +4776,7 @@ networkAllocatePort(virNetworkObjPtr obj,
netdef->name); netdef->name);
goto cleanup; goto cleanup;
} }
if (VIR_STRDUP(port->plug.direct.linkdev, port->plug.direct.linkdev = g_strdup(dev->device.dev);
dev->device.dev) < 0)
goto cleanup;
} }
break; break;

View File

@ -151,16 +151,14 @@ main(int argc, char **argv)
clientid = argv[2]; clientid = argv[2];
} }
if (VIR_STRDUP(server_duid, getenv("DNSMASQ_SERVER_DUID")) < 0) server_duid = g_strdup(getenv("DNSMASQ_SERVER_DUID"));
goto cleanup;
if (virAsprintf(&custom_lease_file, if (virAsprintf(&custom_lease_file,
LOCALSTATEDIR "/lib/libvirt/dnsmasq/%s.status", LOCALSTATEDIR "/lib/libvirt/dnsmasq/%s.status",
interface) < 0) interface) < 0)
goto cleanup; goto cleanup;
if (VIR_STRDUP(pid_file, RUNSTATEDIR "/leaseshelper.pid") < 0) pid_file = g_strdup(RUNSTATEDIR "/leaseshelper.pid");
goto cleanup;
/* Try to claim the pidfile, exiting if we can't */ /* Try to claim the pidfile, exiting if we can't */
if ((pid_file_fd = virPidFileAcquirePath(pid_file, false, getpid())) < 0) if ((pid_file_fd = virPidFileAcquirePath(pid_file, false, getpid())) < 0)