[PATCH v3 07/34] Adapt to VIR_STRDUP and VIR_STRNDUP in src/libxl/*

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

 



---
 src/libxl/libxl_conf.c   | 86 ++++++++++++++----------------------------------
 src/libxl/libxl_driver.c | 14 +++-----
 2 files changed, 29 insertions(+), 71 deletions(-)

diff --git a/src/libxl/libxl_conf.c b/src/libxl/libxl_conf.c
index 3de642b..be7ccaa 100644
--- a/src/libxl/libxl_conf.c
+++ b/src/libxl/libxl_conf.c
@@ -302,10 +302,8 @@ libxlMakeDomCreateInfo(libxlDriverPrivatePtr driver,
     else
         c_info->type = LIBXL_DOMAIN_TYPE_PV;
 
-    if ((c_info->name = strdup(def->name)) == NULL) {
-        virReportOOMError();
+    if (VIR_STRDUP(c_info->name, def->name) < 0)
         goto error;
-    }
 
     if (def->nseclabels &&
         def->seclabels[0]->type == VIR_DOMAIN_SECLABEL_STATIC) {
@@ -403,10 +401,8 @@ libxlMakeDomBuildInfo(virDomainDefPtr def, libxl_domain_config *d_config)
         else {
             bootorder[def->os.nBootDevs] = '\0';
         }
-        if ((b_info->u.hvm.boot = strdup(bootorder)) == NULL) {
-            virReportOOMError();
+        if (VIR_STRDUP(b_info->u.hvm.boot, bootorder) < 0)
             goto error;
-        }
 
         /*
          * The following comment and calculation were taken directly from
@@ -418,37 +414,26 @@ 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)
+            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)
+            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) {
-                virReportOOMError();
+            if (VIR_STRDUP(b_info->u.pv.kernel, def->os.kernel) < 0)
                 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)
+            goto error;
     }
 
     return 0;
@@ -461,15 +446,11 @@ error:
 int
 libxlMakeDisk(virDomainDiskDefPtr l_disk, libxl_device_disk *x_disk)
 {
-    if (l_disk->src && (x_disk->pdev_path = strdup(l_disk->src)) == NULL) {
-        virReportOOMError();
+    if (l_disk->src && VIR_STRDUP(x_disk->pdev_path, l_disk->src) < 0)
         return -1;
-    }
 
-    if (l_disk->dst && (x_disk->vdev = strdup(l_disk->dst)) == NULL) {
-        virReportOOMError();
+    if (l_disk->dst && VIR_STRDUP(x_disk->vdev, l_disk->dst) < 0)
         return -1;
-    }
 
     if (l_disk->driverName) {
         if (STREQ(l_disk->driverName, "tap") ||
@@ -575,31 +556,22 @@ 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) {
-            virReportOOMError();
+        if (VIR_STRDUP(x_nic->model, l_nic->model) < 0)
             return -1;
-        }
         x_nic->nictype = LIBXL_NIC_TYPE_VIF_IOEMU;
     } else {
         x_nic->nictype = LIBXL_NIC_TYPE_VIF;
     }
 
-    if (l_nic->ifname && (x_nic->ifname = strdup(l_nic->ifname)) == NULL) {
-        virReportOOMError();
+    if (l_nic->ifname && VIR_STRDUP(x_nic->ifname, l_nic->ifname) < 0)
         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) {
-            virReportOOMError();
+            VIR_STRDUP(x_nic->bridge, l_nic->data.bridge.brname) < 0)
             return -1;
-        }
-        if (l_nic->script &&
-            (x_nic->script = strdup(l_nic->script)) == NULL) {
-            virReportOOMError();
+        if (l_nic->script && VIR_STRDUP(x_nic->script, l_nic->script) < 0)
             return -1;
-        }
     } else {
         if (l_nic->script) {
             virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
@@ -656,16 +628,11 @@ 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) {
-                virReportOOMError();
+                VIR_STRDUP(x_vfb->sdl.display, l_vfb->data.sdl.display) < 0)
                 return -1;
-            }
             if (l_vfb->data.sdl.xauth &&
-                (x_vfb->sdl.xauthority =
-                    strdup(l_vfb->data.sdl.xauth)) == NULL) {
-                virReportOOMError();
+                VIR_STRDUP(x_vfb->sdl.xauthority, l_vfb->data.sdl.xauth) < 0)
                 return -1;
-            }
             break;
         case  VIR_DOMAIN_GRAPHICS_TYPE_VNC:
             libxl_defbool_set(&x_vfb->vnc.enable, 1);
@@ -686,19 +653,14 @@ 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) {
-                    virReportOOMError();
+                if (VIR_STRDUP(x_vfb->vnc.listen, listenAddr) < 0)
                     return -1;
-                }
             }
             if (l_vfb->data.vnc.keymap &&
-                (x_vfb->keymap =
-                    strdup(l_vfb->data.vnc.keymap)) == NULL) {
-                virReportOOMError();
+                VIR_STRDUP(x_vfb->keymap, l_vfb->data.vnc.keymap) < 0)
                 return -1;
-            }
             break;
     }
 
diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c
index 7361743..be01a4b 100644
--- a/src/libxl/libxl_driver.c
+++ b/src/libxl/libxl_driver.c
@@ -1881,8 +1881,7 @@ libxlDomainGetOSType(virDomainPtr dom)
         goto cleanup;
     }
 
-    if (!(type = strdup(vm->def->os.type)))
-        virReportOOMError();
+    ignore_value(VIR_STRDUP(type, vm->def->os.type));
 
 cleanup:
     if (vm)
@@ -3879,18 +3878,18 @@ libxlDomainGetSchedulerType(virDomainPtr dom, int *nparams)
         *nparams = 0;
     switch (sched_id) {
     case LIBXL_SCHEDULER_SEDF:
-        ret = strdup("sedf");
+        ignore_value(VIR_STRDUP(ret, "sedf"));
         break;
     case LIBXL_SCHEDULER_CREDIT:
-        ret = strdup("credit");
+        ignore_value(VIR_STRDUP(ret, "credit"));
         if (nparams)
             *nparams = XEN_SCHED_CREDIT_NPARAM;
         break;
     case LIBXL_SCHEDULER_CREDIT2:
-        ret = strdup("credit2");
+        ignore_value(VIR_STRDUP(ret, "credit2"));
         break;
     case LIBXL_SCHEDULER_ARINC653:
-        ret = strdup("arinc653");
+        ignore_value(VIR_STRDUP(ret, "arinc653"));
         break;
     default:
         virReportError(VIR_ERR_INTERNAL_ERROR,
@@ -3899,9 +3898,6 @@ libxlDomainGetSchedulerType(virDomainPtr dom, int *nparams)
         goto cleanup;
     }
 
-    if (!ret)
-        virReportOOMError();
-
 cleanup:
     if (vm)
         virObjectUnlock(vm);
-- 
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]