[PATCH v2 08/37] Adapt to VIR_STRDUP in src/libxl/*

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

 



---
 src/libxl/libxl_conf.c   | 59 ++++++++++++++++++++++--------------------------
 src/libxl/libxl_driver.c | 13 ++++++-----
 2 files changed, 34 insertions(+), 38 deletions(-)

diff --git a/src/libxl/libxl_conf.c b/src/libxl/libxl_conf.c
index 7e0753a..19d40f3 100644
--- a/src/libxl/libxl_conf.c
+++ b/src/libxl/libxl_conf.c
@@ -302,7 +302,7 @@ libxlMakeDomCreateInfo(libxlDriverPrivatePtr driver,
     else
         c_info->type = LIBXL_DOMAIN_TYPE_PV;
 
-    if ((c_info->name = strdup(def->name)) == NULL) {
+    if (VIR_STRDUP(c_info->name, def->name) < 0) {
         virReportOOMError();
         goto error;
     }
@@ -403,7 +403,7 @@ libxlMakeDomBuildInfo(virDomainDefPtr def, libxl_domain_config *d_config)
         else {
             bootorder[def->os.nBootDevs] = '\0';
         }
-        if ((b_info->u.hvm.boot = strdup(bootorder)) == NULL) {
+        if (VIR_STRDUP(b_info->u.hvm.boot, bootorder) < 0) {
             virReportOOMError();
             goto error;
         }
@@ -418,36 +418,33 @@ libxlMakeDomBuildInfo(virDomainDefPtr def, libxl_domain_config *d_config)
         b_info->shadow_memkb = 4 * (256 * libxl_bitmap_count_set(&b_info->avail_vcpus) +
                                     2 * (b_info->max_memkb / 1024));
     } else {
-        if (def->os.bootloader) {
-            if ((b_info->u.pv.bootloader = strdup(def->os.bootloader)) == NULL) {
-                virReportOOMError();
-                goto error;
-            }
+        if (def->os.bootloader &&
+            VIR_STRDUP(b_info->u.pv.bootloader, def->os.bootloader) < 0) {
+            virReportOOMError();
+            goto error;
         }
         if (def->os.bootloaderArgs) {
             if (!(b_info->u.pv.bootloader_args =
                   virStringSplit(def->os.bootloaderArgs, " \t\n", 0)))
                 goto error;
         }
-        if (def->os.cmdline) {
-            if ((b_info->u.pv.cmdline = strdup(def->os.cmdline)) == NULL) {
-                virReportOOMError();
-                goto error;
-            }
+        if (def->os.cmdline &&
+            VIR_STRDUP(b_info->u.pv.cmdline, def->os.cmdline) < 0) {
+            virReportOOMError();
+            goto error;
         }
         if (def->os.kernel) {
-            /* libxl_init_build_info() sets kernel.path = strdup("hvmloader") */
+            /* libxl_init_build_info() sets VIR_STRDUP(kernel.path, "hvmloader") */
             VIR_FREE(b_info->u.pv.kernel);
-            if ((b_info->u.pv.kernel = strdup(def->os.kernel)) == NULL) {
+            if (VIR_STRDUP(b_info->u.pv.kernel, def->os.kernel) < 0) {
                 virReportOOMError();
                 goto error;
             }
         }
-        if (def->os.initrd) {
-            if ((b_info->u.pv.ramdisk = strdup(def->os.initrd)) == NULL) {
-                virReportOOMError();
-                goto error;
-            }
+        if (def->os.initrd &&
+            VIR_STRDUP(b_info->u.pv.ramdisk, def->os.initrd) < 0) {
+            virReportOOMError();
+            goto error;
         }
     }
 
@@ -461,12 +458,12 @@ error:
 int
 libxlMakeDisk(virDomainDiskDefPtr l_disk, libxl_device_disk *x_disk)
 {
-    if (l_disk->src && (x_disk->pdev_path = strdup(l_disk->src)) == NULL) {
+    if (l_disk->src && VIR_STRDUP(x_disk->pdev_path, l_disk->src) < 0) {
         virReportOOMError();
         return -1;
     }
 
-    if (l_disk->dst && (x_disk->vdev = strdup(l_disk->dst)) == NULL) {
+    if (l_disk->dst && VIR_STRDUP(x_disk->vdev, l_disk->dst) < 0) {
         virReportOOMError();
         return -1;
     }
@@ -575,7 +572,7 @@ libxlMakeNic(virDomainNetDefPtr l_nic, libxl_device_nic *x_nic)
     virMacAddrGetRaw(&l_nic->mac, x_nic->mac);
 
     if (l_nic->model && !STREQ(l_nic->model, "netfront")) {
-        if ((x_nic->model = strdup(l_nic->model)) == NULL) {
+        if (VIR_STRDUP(x_nic->model, l_nic->model) < 0) {
             virReportOOMError();
             return -1;
         }
@@ -584,19 +581,19 @@ libxlMakeNic(virDomainNetDefPtr l_nic, libxl_device_nic *x_nic)
         x_nic->nictype = LIBXL_NIC_TYPE_VIF;
     }
 
-    if (l_nic->ifname && (x_nic->ifname = strdup(l_nic->ifname)) == NULL) {
+    if (l_nic->ifname && VIR_STRDUP(x_nic->ifname, l_nic->ifname) < 0) {
         virReportOOMError();
         return -1;
     }
 
     if (l_nic->type == VIR_DOMAIN_NET_TYPE_BRIDGE) {
         if (l_nic->data.bridge.brname &&
-            (x_nic->bridge = strdup(l_nic->data.bridge.brname)) == NULL) {
+            VIR_STRDUP(x_nic->bridge, l_nic->data.bridge.brname) < 0) {
             virReportOOMError();
             return -1;
         }
         if (l_nic->script &&
-            (x_nic->script = strdup(l_nic->script)) == NULL) {
+            VIR_STRDUP(x_nic->script, l_nic->script) < 0) {
             virReportOOMError();
             return -1;
         }
@@ -656,13 +653,12 @@ libxlMakeVfb(libxlDriverPrivatePtr driver,
         case VIR_DOMAIN_GRAPHICS_TYPE_SDL:
             libxl_defbool_set(&x_vfb->sdl.enable, 1);
             if (l_vfb->data.sdl.display &&
-                (x_vfb->sdl.display = strdup(l_vfb->data.sdl.display)) == NULL) {
+                VIR_STRDUP(x_vfb->sdl.display, l_vfb->data.sdl.display) < 0) {
                 virReportOOMError();
                 return -1;
             }
             if (l_vfb->data.sdl.xauth &&
-                (x_vfb->sdl.xauthority =
-                    strdup(l_vfb->data.sdl.xauth)) == NULL) {
+                VIR_STRDUP(x_vfb->sdl.xauthority, l_vfb->data.sdl.xauth) < 0) {
                 virReportOOMError();
                 return -1;
             }
@@ -686,16 +682,15 @@ libxlMakeVfb(libxlDriverPrivatePtr driver,
 
             listenAddr = virDomainGraphicsListenGetAddress(l_vfb, 0);
             if (listenAddr) {
-                /* libxl_device_vfb_init() does strdup("127.0.0.1") */
+                /* libxl_device_vfb_init() does VIR_STRDUP(("127.0.0.1") */
                 VIR_FREE(x_vfb->vnc.listen);
-                if ((x_vfb->vnc.listen = strdup(listenAddr)) == NULL) {
+                if (VIR_STRDUP(x_vfb->vnc.listen, listenAddr) < 0) {
                     virReportOOMError();
                     return -1;
                 }
             }
             if (l_vfb->data.vnc.keymap &&
-                (x_vfb->keymap =
-                    strdup(l_vfb->data.vnc.keymap)) == NULL) {
+                VIR_STRDUP(x_vfb->keymap, l_vfb->data.vnc.keymap) < 0) {
                 virReportOOMError();
                 return -1;
             }
diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c
index 7361743..a73aff5 100644
--- a/src/libxl/libxl_driver.c
+++ b/src/libxl/libxl_driver.c
@@ -1881,7 +1881,7 @@ libxlDomainGetOSType(virDomainPtr dom)
         goto cleanup;
     }
 
-    if (!(type = strdup(vm->def->os.type)))
+    if (VIR_STRDUP(type, vm->def->os.type) < 0)
         virReportOOMError();
 
 cleanup:
@@ -3856,6 +3856,7 @@ libxlDomainGetSchedulerType(virDomainPtr dom, int *nparams)
     libxlDomainObjPrivatePtr priv;
     virDomainObjPtr vm;
     char * ret = NULL;
+    int rc;
     libxl_scheduler sched_id;
 
     libxlDriverLock(driver);
@@ -3879,18 +3880,18 @@ libxlDomainGetSchedulerType(virDomainPtr dom, int *nparams)
         *nparams = 0;
     switch (sched_id) {
     case LIBXL_SCHEDULER_SEDF:
-        ret = strdup("sedf");
+        rc = VIR_STRDUP(ret, "sedf");
         break;
     case LIBXL_SCHEDULER_CREDIT:
-        ret = strdup("credit");
+        rc = VIR_STRDUP(ret, "credit");
         if (nparams)
             *nparams = XEN_SCHED_CREDIT_NPARAM;
         break;
     case LIBXL_SCHEDULER_CREDIT2:
-        ret = strdup("credit2");
+        rc = VIR_STRDUP(ret, "credit2");
         break;
     case LIBXL_SCHEDULER_ARINC653:
-        ret = strdup("arinc653");
+        rc = VIR_STRDUP(ret, "arinc653");
         break;
     default:
         virReportError(VIR_ERR_INTERNAL_ERROR,
@@ -3899,7 +3900,7 @@ libxlDomainGetSchedulerType(virDomainPtr dom, int *nparams)
         goto cleanup;
     }
 
-    if (!ret)
+    if (rc < 0)
         virReportOOMError();
 
 cleanup:
-- 
1.8.1.5

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]