[PATCH v2 31/37] Adapt to VIR_STRDUP in src/xenapi/*

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

 



---
 src/xenapi/xenapi_driver.c | 32 +++++++++++++++-----------------
 src/xenapi/xenapi_utils.c  | 20 ++++++++++----------
 2 files changed, 25 insertions(+), 27 deletions(-)

diff --git a/src/xenapi/xenapi_driver.c b/src/xenapi/xenapi_driver.c
index 7e64df6..86abab8 100644
--- a/src/xenapi/xenapi_driver.c
+++ b/src/xenapi/xenapi_driver.c
@@ -135,9 +135,7 @@ xenapiConnectOpen(virConnectPtr conn, virConnectAuthPtr auth,
     }
 
     if (conn->uri->user != NULL) {
-        username = strdup(conn->uri->user);
-
-        if (username == NULL) {
+        if (VIR_STRDUP(username, conn->uri->user) < 0) {
             virReportOOMError();
             goto error;
         }
@@ -320,7 +318,7 @@ xenapiConnectGetVersion(virConnectPtr conn, unsigned long *hvVer)
     if (result && result->size > 0) {
         for (i = 0; i < result->size; i++) {
             if (STREQ(result->contents[i].key, "xen")) {
-                if (!(version = strdup(result->contents[i].val))) {
+                if (VIR_STRDUP(version, result->contents[i].val) < 0) {
                     xen_string_string_map_free(result);
                     virReportOOMError();
                     return -1;
@@ -952,7 +950,7 @@ xenapiDomainGetOSType(virDomainPtr dom)
             xenapiSessionErrorHandler(dom->conn, VIR_ERR_INTERNAL_ERROR, NULL);
             goto cleanup;
         }
-        if (!(ostype = (STREQ(boot_policy,"BIOS order") ? strdup("hvm") : strdup("xen"))))
+        if (VIR_STRDUP(ostype, STREQ(boot_policy, "BIOS order") ? "hvm" : "xen") < 0)
             virReportOOMError();
         VIR_FREE(boot_policy);
     } else
@@ -1268,7 +1266,7 @@ xenapiDomainGetVcpus(virDomainPtr dom,
     }
     for (i = 0; i < vcpu_params->size; i++) {
         if (STREQ(vcpu_params->contents[i].key, "mask")) {
-            if (!(mask = strdup(vcpu_params->contents[i].val))){
+            if (VIR_STRDUP(mask, vcpu_params->contents[i].val) < 0){
                  xen_vm_set_free(vms);
                  xen_string_string_map_free(vcpu_params);
                  virReportOOMError();
@@ -1386,11 +1384,11 @@ xenapiDomainGetXMLDesc(virDomainPtr dom, unsigned int flags)
     defPtr->virtType = VIR_DOMAIN_VIRT_XEN;
     defPtr->id = dom->id;
     memcpy(defPtr->uuid, dom->uuid, VIR_UUID_BUFLEN);
-    if (!(defPtr->name = strdup(dom->name)))
+    if (VIR_STRDUP(defPtr->name, dom->name) < 0)
         goto error_cleanup;
     xen_vm_get_hvm_boot_policy(session, &boot_policy, vm);
     if (STREQ(boot_policy,"BIOS order")) {
-        if (!(defPtr->os.type = strdup("hvm"))) {
+        if (VIR_STRDUP(defPtr->os.type, "hvm") < 0) {
             VIR_FREE(boot_policy);
             goto error_cleanup;
         }
@@ -1413,17 +1411,17 @@ xenapiDomainGetXMLDesc(virDomainPtr dom, unsigned int flags)
         VIR_FREE(boot_policy);
     } else {
         char *value = NULL;
-        if (!(defPtr->os.type = strdup("xen"))) {
+        if (VIR_STRDUP(defPtr->os.type, "xen") < 0) {
             VIR_FREE(boot_policy);
             goto error_cleanup;
         }
-        if (!(defPtr->os.loader = strdup("pygrub"))) {
+        if (VIR_STRDUP(defPtr->os.loader, "pygrub") < 0) {
             VIR_FREE(boot_policy);
             goto error_cleanup;
         }
         xen_vm_get_pv_kernel(session, &value, vm);
         if (STRNEQ(value, "")) {
-            if (!(defPtr->os.kernel = strdup(value))) {
+            if (VIR_STRDUP(defPtr->os.kernel, value) < 0) {
                 VIR_FREE(boot_policy);
                 VIR_FREE(value);
                 goto error_cleanup;
@@ -1432,7 +1430,7 @@ xenapiDomainGetXMLDesc(virDomainPtr dom, unsigned int flags)
         }
         xen_vm_get_pv_ramdisk(session, &value, vm);
         if (STRNEQ(value, "")) {
-            if (!(defPtr->os.initrd = strdup(value))) {
+            if (VIR_STRDUP(defPtr->os.initrd, value) < 0) {
                 VIR_FREE(boot_policy);
                 VIR_FREE(value);
                 goto error_cleanup;
@@ -1441,7 +1439,7 @@ xenapiDomainGetXMLDesc(virDomainPtr dom, unsigned int flags)
         }
         xen_vm_get_pv_args(session, &value, vm);
         if (STRNEQ(value, "")) {
-            if (!(defPtr->os.cmdline = strdup(value))) {
+            if (VIR_STRDUP(defPtr->os.cmdline, value) < 0) {
                 VIR_FREE(boot_policy);
                 VIR_FREE(value);
                 goto error_cleanup;
@@ -1449,12 +1447,12 @@ xenapiDomainGetXMLDesc(virDomainPtr dom, unsigned int flags)
             VIR_FREE(value);
         }
         VIR_FREE(boot_policy);
-        if (!(defPtr->os.bootloader = strdup("pygrub")))
+        if (VIR_STRDUP(defPtr->os.bootloader, "pygrub") < 0)
             goto error_cleanup;
     }
     xen_vm_get_pv_bootloader_args(session, &val, vm);
     if (STRNEQ(val, "")) {
-        if (!(defPtr->os.bootloaderArgs = strdup(val))) {
+        if (VIR_STRDUP(defPtr->os.bootloaderArgs, val) < 0) {
             VIR_FREE(val);
             goto error_cleanup;
         }
@@ -1569,7 +1567,7 @@ xenapiConnectListDefinedDomains(virConnectPtr conn, char **const names,
             if (record != NULL) {
                 if (record->is_a_template == 0) {
                     char *usenames = NULL;
-                    if (!(usenames = strdup(record->name_label))) {
+                    if (VIR_STRDUP(usenames, record->name_label) < 0) {
                         virReportOOMError();
                         xen_vm_record_free(record);
                         xen_vm_set_free(result);
@@ -1862,7 +1860,7 @@ xenapiDomainGetSchedulerType(virDomainPtr dom ATTRIBUTE_UNUSED, int *nparams)
 
     if (nparams)
         *nparams = 0;
-    if (!(result = strdup("credit")))
+    if (VIR_STRDUP(result, "credit") < 0)
         virReportOOMError();
     return result;
 }
diff --git a/src/xenapi/xenapi_utils.c b/src/xenapi/xenapi_utils.c
index 55fbb24..8dc0873 100644
--- a/src/xenapi/xenapi_utils.c
+++ b/src/xenapi/xenapi_utils.c
@@ -352,8 +352,8 @@ allocStringMap(xen_string_string_map **strings, char *key, char *val)
         return -1;
     }
     (*strings)->size = sz;
-    if (!((*strings)->contents[sz-1].key = strdup(key))) goto error;
-    if (!((*strings)->contents[sz-1].val = strdup(val))) goto error;
+    if (VIR_STRDUP((*strings)->contents[sz-1].key, key) < 0) goto error;
+    if (VIR_STRDUP((*strings)->contents[sz-1].val, val) < 0) goto error;
     return 0;
   error:
     xen_string_string_map_free(*strings);
@@ -455,16 +455,16 @@ createVMRecordFromXml(virConnectPtr conn, virDomainDefPtr def,
     int i;
 
     *record = xen_vm_record_alloc();
-    if (!((*record)->name_label = strdup(def->name)))
+    if (VIR_STRDUP((*record)->name_label, def->name) < 0)
         goto error_cleanup;
     if (def->uuid) {
         virUUIDFormat(def->uuid, uuidStr);
-        if (!((*record)->uuid = strdup(uuidStr)))
+        if (VIR_STRDUP((*record)->uuid, uuidStr) < 0)
             goto error_cleanup;
     }
     if (STREQ(def->os.type, "hvm")) {
         char *boot_order = NULL;
-        if (!((*record)->hvm_boot_policy = strdup("BIOS order")))
+        if (VIR_STRDUP((*record)->hvm_boot_policy, "BIOS order") < 0)
             goto error_cleanup;
         if (def->os.nBootDevs != 0)
             boot_order = createXenAPIBootOrderString(def->os.nBootDevs, &def->os.bootDevs[0]);
@@ -475,24 +475,24 @@ createVMRecordFromXml(virConnectPtr conn, virDomainDefPtr def,
             VIR_FREE(boot_order);
         }
     } else if (STREQ(def->os.type, "xen")) {
-        if (!((*record)->pv_bootloader = strdup("pygrub")))
+        if (VIR_STRDUP((*record)->pv_bootloader, "pygrub") < 0)
             goto error_cleanup;
         if (def->os.kernel) {
-            if (!((*record)->pv_kernel = strdup(def->os.kernel)))
+            if (VIR_STRDUP((*record)->pv_kernel, def->os.kernel) < 0)
                 goto error_cleanup;
         }
         if (def->os.initrd) {
-            if (!((*record)->pv_ramdisk = strdup(def->os.initrd)))
+            if (VIR_STRDUP((*record)->pv_ramdisk, def->os.initrd) < 0)
                 goto error_cleanup;
         }
         if (def->os.cmdline) {
-            if (!((*record)->pv_args = strdup(def->os.cmdline)))
+            if (VIR_STRDUP((*record)->pv_args, def->os.cmdline) < 0)
                 goto error_cleanup;
         }
         (*record)->hvm_boot_params = xen_string_string_map_alloc(0);
     }
     if (def->os.bootloaderArgs)
-        if (!((*record)->pv_bootloader_args = strdup(def->os.bootloaderArgs)))
+        if (VIR_STRDUP((*record)->pv_bootloader_args, def->os.bootloaderArgs) < 0)
             goto error_cleanup;
 
     if (def->mem.cur_balloon)
-- 
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]