esx: use g_new0 instead of VIR_ALLOC*

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
This commit is contained in:
Ján Tomko 2020-09-23 20:44:04 +02:00
parent 9dceef831a
commit 3f8a30cd7d
8 changed files with 23 additions and 43 deletions

View 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;

View 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 ||

View 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;

View 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,

View 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;

View 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];

View 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;

View 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; \
\