[PATCH v1 33/37] Adapt to VIR_ALLOC and virAsprintf in src/xenapi/*

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

 



---
 src/xenapi/xenapi_driver.c | 29 ++++++++---------------------
 src/xenapi/xenapi_utils.c  | 11 ++++-------
 2 files changed, 12 insertions(+), 28 deletions(-)

diff --git a/src/xenapi/xenapi_driver.c b/src/xenapi/xenapi_driver.c
index cc8da49..869ec76 100644
--- a/src/xenapi/xenapi_driver.c
+++ b/src/xenapi/xenapi_driver.c
@@ -77,10 +77,8 @@ getCapsObject(void)
     virCapsGuestDomainPtr domain1, domain2;
     virCapsPtr caps = virCapabilitiesNew(virArchFromHost(), 0, 0);
 
-    if (!caps) {
-        virReportOOMError();
+    if (!caps)
         return NULL;
-    }
     guest1 = virCapabilitiesAddGuest(caps, "hvm", VIR_ARCH_X86_64, "", "", 0, NULL);
     if (!guest1)
         goto error_cleanup;
@@ -155,15 +153,11 @@ xenapiConnectOpen(virConnectPtr conn, virConnectAuthPtr auth,
         goto error;
     }
 
-    if (VIR_ALLOC(privP) < 0) {
-        virReportOOMError();
+    if (VIR_ALLOC(privP) < 0)
         goto error;
-    }
 
-    if (virAsprintf(&privP->url, "https://%s";, conn->uri->server) < 0) {
-        virReportOOMError();
+    if (virAsprintf(&privP->url, "https://%s";, conn->uri->server) < 0)
         goto error;
-    }
 
     if (xenapiUtil_ParseQuery(conn, conn->uri, &privP->noVerify) < 0)
         goto error;
@@ -409,12 +403,9 @@ xenapiNodeGetInfo(virConnectPtr conn, virNodeInfoPtr info)
     if (xen_host_cpu_get_all(session, &host_cpu_set)) {
         host_cpu = host_cpu_set->contents[0];
         xen_host_cpu_get_modelname(session, &modelname, host_cpu);
-        if (!virStrncpy(info->model, modelname, LIBVIRT_MODELNAME_LEN - 1, LIBVIRT_MODELNAME_LEN)) {
-            virReportOOMError();
-            xen_host_cpu_set_free(host_cpu_set);
-            VIR_FREE(modelname);
-            return -1;
-        }
+        ignore_value(virStrncpy(info->model, modelname,
+                                LIBVIRT_MODELNAME_LEN - 1,
+                                LIBVIRT_MODELNAME_LEN));
         xen_host_cpu_get_speed(session, &mhz, host_cpu);
         info->mhz = (unsigned long)mhz;
         info->cpus = host_cpu_set->size;
@@ -1372,7 +1363,6 @@ xenapiDomainGetXMLDesc(virDomainPtr dom, unsigned int flags)
         return NULL;
     }
     if (VIR_ALLOC(defPtr) < 0) {
-        virReportOOMError();
         xen_vm_set_free(vms);
         return NULL;
     }
@@ -1502,12 +1492,12 @@ xenapiDomainGetXMLDesc(virDomainPtr dom, unsigned int flags)
         defPtr->nnets = vif_set->size;
         if (VIR_ALLOC_N(defPtr->nets, vif_set->size) < 0) {
             xen_vif_set_free(vif_set);
-            goto error_cleanup;
+            goto error;
         }
         for (i = 0; i < vif_set->size; i++) {
             if (VIR_ALLOC(defPtr->nets[i]) < 0) {
                 xen_vif_set_free(vif_set);
-                goto error_cleanup;
+                goto error;
             }
             defPtr->nets[i]->type = VIR_DOMAIN_NET_TYPE_BRIDGE;
             vif = vif_set->contents[i];
@@ -1534,13 +1524,10 @@ xenapiDomainGetXMLDesc(virDomainPtr dom, unsigned int flags)
     virDomainDefFree(defPtr);
     return xml;
 
-  error_cleanup:
-    virReportOOMError();
   error:
     xen_vm_set_free(vms);
     virDomainDefFree(defPtr);
     return NULL;
-
 }
 
 /*
diff --git a/src/xenapi/xenapi_utils.c b/src/xenapi/xenapi_utils.c
index 46e1aea..bf3dcaf 100644
--- a/src/xenapi/xenapi_utils.c
+++ b/src/xenapi/xenapi_utils.c
@@ -347,10 +347,8 @@ allocStringMap(xen_string_string_map **strings, char *key, char *val)
     int sz = ((*strings) == NULL) ? 0 : (*strings)->size;
     sz++;
     if (VIR_REALLOC_N(*strings, sizeof(xen_string_string_map) +
-                                sizeof(xen_string_string_map_contents) * sz) < 0) {
-        virReportOOMError();
+                                sizeof(xen_string_string_map_contents) * sz) < 0)
         return -1;
-    }
     (*strings)->size = sz;
     if (VIR_STRDUP((*strings)->contents[sz-1].key, key) < 0 ||
         VIR_STRDUP((*strings)->contents[sz-1].val, val) < 0)
@@ -545,22 +543,21 @@ createVMRecordFromXml(virConnectPtr conn, virDomainDefPtr def,
             char *mac;
 
             if (VIR_ALLOC_N(mac, VIR_MAC_STRING_BUFLEN) < 0)
-                goto error_cleanup;
+                goto error;
             virMacAddrFormat(&def->nets[i]->mac, mac);
 
             if (createVifNetwork(conn, *vm, device_number,
                                  def->nets[i]->data.bridge.brname,
                                  mac) < 0) {
                 VIR_FREE(mac);
-                goto error_cleanup;
+                virReportOOMError();
+                goto error;
             }
             device_number++;
         }
     }
     return 0;
 
-  error_cleanup:
-    virReportOOMError();
   error:
     xen_vm_record_free(*record);
     return -1;
-- 
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]