[libvirt PATCH 2/7] esx: use g_new0 instead of VIR_ALLOC*

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

 



Signed-off-by: Ján Tomko <jtomko@xxxxxxxxxx>
---
 src/esx/esx_driver.c                | 14 +++++---------
 src/esx/esx_network_driver.c        | 17 ++++++-----------
 src/esx/esx_storage_backend_iscsi.c |  3 +--
 src/esx/esx_storage_backend_vmfs.c  |  8 +++-----
 src/esx/esx_stream.c                |  6 ++----
 src/esx/esx_util.c                  |  3 +--
 src/esx/esx_vi.c                    | 12 ++++--------
 src/esx/esx_vi_types.c              |  3 +--
 8 files changed, 23 insertions(+), 43 deletions(-)

diff --git a/src/esx/esx_driver.c b/src/esx/esx_driver.c
index 5a742ed3df..e82e5ed835 100644
--- a/src/esx/esx_driver.c
+++ b/src/esx/esx_driver.c
@@ -824,8 +824,7 @@ esxConnectOpen(virConnectPtr conn, virConnectAuthPtr auth,
     }
 
     /* Allocate per-connection private data */
-    if (VIR_ALLOC(priv) < 0)
-        goto cleanup;
+    priv = g_new0(esxPrivate, 1);
 
     if (esxUtil_ParseUri(&priv->parsedUri, conn->uri) < 0)
         goto cleanup;
@@ -4823,9 +4822,8 @@ esxConnectListAllDomains(virConnectPtr conn,
          !MATCH(VIR_CONNECT_LIST_DOMAINS_PERSISTENT)) ||
         (MATCH(VIR_CONNECT_LIST_DOMAINS_MANAGEDSAVE) &&
          !MATCH(VIR_CONNECT_LIST_DOMAINS_NO_MANAGEDSAVE))) {
-        if (domains &&
-            VIR_ALLOC_N(*domains, 1) < 0)
-            goto cleanup;
+        if (domains)
+            *domains = g_new0(virDomainPtr, 1);
 
         ret = 0;
         goto cleanup;
@@ -4885,8 +4883,7 @@ esxConnectListAllDomains(virConnectPtr conn,
         goto cleanup;
 
     if (domains) {
-        if (VIR_ALLOC_N(doms, 1) < 0)
-            goto cleanup;
+        doms = g_new0(virDomainPtr, 1);
         ndoms = 1;
     }
 
@@ -5218,8 +5215,7 @@ esxDomainInterfaceAddresses(virDomainPtr domain,
         if (VIR_EXPAND_N(ifaces_ret, ifaces_count, 1) < 0)
             goto cleanup;
 
-        if (VIR_ALLOC(ifaces_ret[ifaces_count - 1]) < 0)
-            goto cleanup;
+        ifaces_ret[ifaces_count - 1] = g_new0(virDomainInterface, 1);
 
         iface = ifaces_ret[ifaces_count - 1];
         iface->naddrs = 0;
diff --git a/src/esx/esx_network_driver.c b/src/esx/esx_network_driver.c
index a4e738ba72..15fc7931c0 100644
--- a/src/esx/esx_network_driver.c
+++ b/src/esx/esx_network_driver.c
@@ -604,10 +604,9 @@ esxShapingPolicyToBandwidth(esxVI_HostNetworkTrafficShapingPolicy *shapingPolicy
     if (!shapingPolicy || shapingPolicy->enabled != esxVI_Boolean_True)
         return 0;
 
-    if (VIR_ALLOC(*bandwidth) < 0 ||
-        VIR_ALLOC((*bandwidth)->in) < 0 ||
-        VIR_ALLOC((*bandwidth)->out) < 0)
-        return -1;
+    *bandwidth = g_new0(virNetDevBandwidth, 1);
+    (*bandwidth)->in = g_new0(virNetDevBandwidthRate, 1);
+    (*bandwidth)->out = g_new0(virNetDevBandwidthRate, 1);
 
     if (shapingPolicy->averageBandwidth) {
         /* Scale bits per second to kilobytes per second */
@@ -655,8 +654,7 @@ esxNetworkGetXMLDesc(virNetworkPtr network_, unsigned int flags)
     if (esxVI_EnsureSession(priv->primary) < 0)
         return NULL;
 
-    if (VIR_ALLOC(def) < 0)
-        goto cleanup;
+    def = g_new0(virNetworkDef, 1);
 
     /* Lookup HostVirtualSwitch */
     if (esxVI_LookupHostVirtualSwitchByName(priv->primary, network_->name,
@@ -682,9 +680,7 @@ esxNetworkGetXMLDesc(virNetworkPtr network_, unsigned int flags)
 
     if (count > 0) {
         def->forward.type = VIR_NETWORK_FORWARD_BRIDGE;
-
-        if (VIR_ALLOC_N(def->forward.ifs, count) < 0)
-            goto cleanup;
+        def->forward.ifs = g_new0(virNetworkForwardIfDef, count);
 
         /* Find PhysicalNic by key */
         if (esxVI_LookupPhysicalNicList(priv->primary, &physicalNicList) < 0)
@@ -726,8 +722,7 @@ esxNetworkGetXMLDesc(virNetworkPtr network_, unsigned int flags)
     }
 
     if (count > 0) {
-        if (VIR_ALLOC_N(def->portGroups, count) < 0)
-            goto cleanup;
+        def->portGroups = g_new0(virPortGroupDef, count);
 
         /* Lookup Network list and create name list */
         if (esxVI_String_AppendValueToList(&propertyNameList, "name") < 0 ||
diff --git a/src/esx/esx_storage_backend_iscsi.c b/src/esx/esx_storage_backend_iscsi.c
index 017b800f06..edbc65f5c0 100644
--- a/src/esx/esx_storage_backend_iscsi.c
+++ b/src/esx/esx_storage_backend_iscsi.c
@@ -337,8 +337,7 @@ esxStoragePoolGetXMLDesc(virStoragePoolPtr pool, unsigned int flags)
 
     def.source.nhost = 1;
 
-    if (VIR_ALLOC_N(def.source.hosts, def.source.nhost) < 0)
-        goto cleanup;
+    def.source.hosts = g_new0(virStoragePoolSourceHost, def.source.nhost);
 
     def.source.hosts[0].name = target->address;
 
diff --git a/src/esx/esx_storage_backend_vmfs.c b/src/esx/esx_storage_backend_vmfs.c
index a98001d6b2..e397853bf7 100644
--- a/src/esx/esx_storage_backend_vmfs.c
+++ b/src/esx/esx_storage_backend_vmfs.c
@@ -512,8 +512,7 @@ esxStoragePoolGetXMLDesc(virStoragePoolPtr pool, unsigned int flags)
     if (esxVI_LocalDatastoreInfo_DynamicCast(info)) {
         def.type = VIR_STORAGE_POOL_DIR;
     } else if ((nasInfo = esxVI_NasDatastoreInfo_DynamicCast(info))) {
-        if (VIR_ALLOC_N(def.source.hosts, 1) < 0)
-            goto cleanup;
+        def.source.hosts = g_new0(virStoragePoolSourceHost, 1);
         def.type = VIR_STORAGE_POOL_NETFS;
         def.source.nhost = 1;
         def.source.hosts[0].name = nasInfo->nas->remoteHost;
@@ -1016,8 +1015,7 @@ esxStorageVolCreateXML(virStoragePoolPtr pool,
         }
 
         if (priv->primary->hasQueryVirtualDiskUuid) {
-            if (VIR_ALLOC_N(key, VIR_UUID_STRING_BUFLEN) < 0)
-                goto cleanup;
+            key = g_new0(char, VIR_UUID_STRING_BUFLEN);
 
             if (esxVI_QueryVirtualDiskUuid(priv->primary, datastorePath,
                                            priv->primary->datacenter->_reference,
@@ -1196,7 +1194,7 @@ esxStorageVolCreateXMLFrom(virStoragePoolPtr pool,
         }
 
         if (priv->primary->hasQueryVirtualDiskUuid) {
-            if (VIR_ALLOC_N(key, VIR_UUID_STRING_BUFLEN) < 0)
+            key = g_new0(char, VIR_UUID_STRING_BUFLEN);
                 goto cleanup;
 
             if (esxVI_QueryVirtualDiskUuid(priv->primary, datastorePath,
diff --git a/src/esx/esx_stream.c b/src/esx/esx_stream.c
index fe3c42ae02..2e7f979e79 100644
--- a/src/esx/esx_stream.c
+++ b/src/esx/esx_stream.c
@@ -132,8 +132,7 @@ esxVI_CURL_WriteStream(char *input, size_t size, size_t nmemb, void *userdata)
             priv->backlog_size = input_remaining;
             priv->backlog_used = 0;
 
-            if (VIR_ALLOC_N(priv->backlog, priv->backlog_size) < 0)
-                return 0;
+            priv->backlog = g_new0(char, priv->backlog_size);
         } else if (input_remaining > backlog_remaining) {
             priv->backlog_size += input_remaining - backlog_remaining;
 
@@ -409,8 +408,7 @@ esxStreamOpen(virStreamPtr stream, esxPrivate *priv, const char *url,
         return -1;
     }
 
-    if (VIR_ALLOC(streamPriv) < 0)
-        return -1;
+    streamPriv = g_new0(esxStreamPrivate, 1);
 
     streamPriv->mode = mode;
 
diff --git a/src/esx/esx_util.c b/src/esx/esx_util.c
index cd3d8925b9..9100873326 100644
--- a/src/esx/esx_util.c
+++ b/src/esx/esx_util.c
@@ -49,8 +49,7 @@ esxUtil_ParseUri(esxUtil_ParsedUri **parsedUri, virURIPtr uri)
 
     ESX_VI_CHECK_ARG_LIST(parsedUri);
 
-    if (VIR_ALLOC(*parsedUri) < 0)
-        return -1;
+    *parsedUri = g_new0(esxUtil_ParsedUri, 1);
 
     for (i = 0; i < uri->paramsCount; i++) {
         virURIParamPtr queryParam = &uri->params[i];
diff --git a/src/esx/esx_vi.c b/src/esx/esx_vi.c
index f099716d3e..c7af092569 100644
--- a/src/esx/esx_vi.c
+++ b/src/esx/esx_vi.c
@@ -53,8 +53,7 @@ VIR_LOG_INIT("esx.esx_vi");
     { \
         ESX_VI_CHECK_ARG_LIST(ptrptr); \
  \
-        if (VIR_ALLOC(*ptrptr) < 0) \
-            return -1; \
+        *ptrptr = g_new0(esxVI_##_type, 1); \
         return 0; \
     }
 
@@ -182,8 +181,7 @@ esxVI_CURL_Debug(CURL *curl G_GNUC_UNUSED, curl_infotype type,
      * To handle this properly in order to pass the info string to VIR_DEBUG
      * a zero terminated copy of the info string has to be allocated.
      */
-    if (VIR_ALLOC_N(buffer, size + 1) < 0)
-        return 0;
+    buffer = g_new0(char, size + 1);
 
     memcpy(buffer, info, size);
     buffer[size] = '\0';
@@ -861,8 +859,7 @@ esxVI_Context_Connect(esxVI_Context *ctx, const char *url,
     ctx->username = g_strdup(username);
     ctx->password = g_strdup(password);
 
-    if (VIR_ALLOC(ctx->sessionLock) < 0)
-        goto cleanup;
+    ctx->sessionLock = g_new0(virMutex, 1);
 
 
     if (virMutexInit(ctx->sessionLock) < 0) {
@@ -3714,8 +3711,7 @@ esxVI_LookupStorageVolumeKeyByDatastorePath(esxVI_Context *ctx,
                 goto cleanup;
             }
 
-            if (VIR_ALLOC_N(*key, VIR_UUID_STRING_BUFLEN) < 0)
-                goto cleanup;
+            *key = g_new0(char, VIR_UUID_STRING_BUFLEN);
 
             if (esxUtil_ReformatUuid(uuid_string, *key) < 0)
                 goto cleanup;
diff --git a/src/esx/esx_vi_types.c b/src/esx/esx_vi_types.c
index ad40ddf54b..6821587e44 100644
--- a/src/esx/esx_vi_types.c
+++ b/src/esx/esx_vi_types.c
@@ -44,8 +44,7 @@ VIR_LOG_INIT("esx.esx_vi_types");
     { \
         ESX_VI_CHECK_ARG_LIST(ptrptr); \
  \
-        if (VIR_ALLOC(*ptrptr) < 0) \
-            return -1; \
+        *ptrptr = g_new0(esxVI_##__type, 1); \
  \
         (*ptrptr)->_type = esxVI_Type_##__type; \
  \
-- 
2.26.2




[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]

  Powered by Linux