[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCH v2 11/37] Adapt to VIR_STRDUP in src/network/*



---
 src/network/bridge_driver.c | 28 +++++++++++-----------------
 1 file changed, 11 insertions(+), 17 deletions(-)

diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c
index b561e85..1a4029c 100644
--- a/src/network/bridge_driver.c
+++ b/src/network/bridge_driver.c
@@ -378,7 +378,7 @@ networkStateInitialize(bool privileged,
                         "%s/log/libvirt/qemu", LOCALSTATEDIR) == -1)
             goto out_of_memory;
 
-        if ((base = strdup(SYSCONFDIR "/libvirt")) == NULL)
+        if (VIR_STRDUP(base, SYSCONFDIR "/libvirt") < 0)
             goto out_of_memory;
     } else {
         char *userdir = virGetUserCacheDirectory();
@@ -2820,7 +2820,7 @@ static int networkConnectListNetworks(virConnectPtr conn, char **const names, in
     for (i = 0 ; i < driver->networks.count && got < nnames ; i++) {
         virNetworkObjLock(driver->networks.objs[i]);
         if (virNetworkObjIsActive(driver->networks.objs[i])) {
-            if (!(names[got] = strdup(driver->networks.objs[i]->def->name))) {
+            if (VIR_STRDUP(names[got], driver->networks.objs[i]->def->name) < 0) {
                 virNetworkObjUnlock(driver->networks.objs[i]);
                 virReportOOMError();
                 goto cleanup;
@@ -2864,7 +2864,7 @@ static int networkConnectListDefinedNetworks(virConnectPtr conn, char **const na
     for (i = 0 ; i < driver->networks.count && got < nnames ; i++) {
         virNetworkObjLock(driver->networks.objs[i]);
         if (!virNetworkObjIsActive(driver->networks.objs[i])) {
-            if (!(names[got] = strdup(driver->networks.objs[i]->def->name))) {
+            if (VIR_STRDUP(names[got], driver->networks.objs[i]->def->name) < 0) {
                 virNetworkObjUnlock(driver->networks.objs[i]);
                 virReportOOMError();
                 goto cleanup;
@@ -3489,8 +3489,7 @@ static char *networkGetBridgeName(virNetworkPtr net) {
         goto cleanup;
     }
 
-    bridge = strdup(network->def->bridge);
-    if (!bridge)
+    if (VIR_STRDUP(bridge, network->def->bridge) < 0)
         virReportOOMError();
 
 cleanup:
@@ -3678,14 +3677,11 @@ networkCreateInterfacePool(virNetworkDefPtr netdef) {
             (netdef->forward.type == VIR_NETWORK_FORWARD_VEPA) ||
             (netdef->forward.type == VIR_NETWORK_FORWARD_PASSTHROUGH)) {
             netdef->forward.ifs[ii].type = VIR_NETWORK_FORWARD_HOSTDEV_DEVICE_NETDEV;
-            if (vfname[ii]) {
-                netdef->forward.ifs[ii].device.dev = strdup(vfname[ii]);
-                if (!netdef->forward.ifs[ii].device.dev) {
-                    virReportOOMError();
-                    goto finish;
-                }
-            }
-            else {
+            if (vfname[ii] &&
+                VIR_STRDUP(netdef->forward.ifs[ii].device.dev, vfname[ii]) < 0) {
+                virReportOOMError();
+                goto finish;
+            } else {
                 virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                                _("Direct mode types require interface names"));
                 goto finish;
@@ -3828,8 +3824,7 @@ networkAllocateActualDevice(virDomainNetDefPtr iface)
         }
 
         iface->data.network.actual->type = actualType = VIR_DOMAIN_NET_TYPE_BRIDGE;
-        iface->data.network.actual->data.bridge.brname = strdup(netdef->bridge);
-        if (!iface->data.network.actual->data.bridge.brname) {
+        if (VIR_STRDUP(iface->data.network.actual->data.bridge.brname, netdef->bridge) < 0) {
             virReportOOMError();
             goto error;
         }
@@ -4049,8 +4044,7 @@ networkAllocateActualDevice(virDomainNetDefPtr iface)
                                netdef->name);
                 goto error;
             }
-            iface->data.network.actual->data.direct.linkdev = strdup(dev->device.dev);
-            if (!iface->data.network.actual->data.direct.linkdev) {
+            if (VIR_STRDUP(iface->data.network.actual->data.direct.linkdev, dev->device.dev) < 0) {
                 virReportOOMError();
                 goto error;
             }
-- 
1.8.1.5


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]