]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
esx: use g_new0 instead of VIR_ALLOC*
authorJán Tomko <jtomko@redhat.com>
Wed, 23 Sep 2020 18:44:04 +0000 (20:44 +0200)
committerJán Tomko <jtomko@redhat.com>
Thu, 1 Oct 2020 10:34:13 +0000 (12:34 +0200)
Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
src/esx/esx_driver.c
src/esx/esx_network_driver.c
src/esx/esx_storage_backend_iscsi.c
src/esx/esx_storage_backend_vmfs.c
src/esx/esx_stream.c
src/esx/esx_util.c
src/esx/esx_vi.c
src/esx/esx_vi_types.c

index 5a742ed3dfe61e12dab03f2c53f2f0a7297f20e1..e82e5ed8359d7d769e51da58943d1c90a591674d 100644 (file)
@@ -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;
index a4e738ba72205bd4a761b8a30ac5309910f609b7..15fc7931c04b6a7d9ae8cf8f7624b2c5aa3932ed 100644 (file)
@@ -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 ||
index 017b800f066f5714a1ef0146c838c49374be06bb..edbc65f5c0deec1b06103f00585fe2943f0ef07f 100644 (file)
@@ -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;
 
index a98001d6b2c3279ce84b75aac1cc42f9098c554e..e397853bf7e030dd8b59fcee028025038b1aabe5 100644 (file)
@@ -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,
index fe3c42ae026e079bd5ba0b2b9044b50d4dacad69..2e7f979e7999877a49fbd30c30181dd86eeb5d32 100644 (file)
@@ -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;
 
index cd3d8925b94ac95a948bb709fbc52b7f0056a2be..91008733261f17abf2fb211a2e32a9cdd3f5d5b3 100644 (file)
@@ -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];
index f099716d3e68549c63c761fcfb78895dac660646..c7af0925693ae7d5db63f1913106266a0f21bb0d 100644 (file)
@@ -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;
index ad40ddf54b3b0882b3921ce55d2f9a7f6429f6a3..6821587e447c1da06271cb9e7fc896eb8552e3cb 100644 (file)
@@ -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; \
  \