1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2025-08-24 09:49:59 +03:00

esx: use g_strdup instead of VIR_STRDUP

Replace all occurrences of
  if (VIR_STRDUP(a, b) < 0)
     /* effectively dead code */
with:
  a = g_strdup(b);

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Ján Tomko
2019-10-20 13:49:46 +02:00
parent 923ab677b2
commit 07ef88935a
8 changed files with 77 additions and 155 deletions

View File

@ -177,8 +177,7 @@ esxParseVMXFileName(const char *fileName, void *opaque)
while (*tmp == '/' || *tmp == '\\') while (*tmp == '/' || *tmp == '\\')
++tmp; ++tmp;
if (VIR_STRDUP(strippedFileName, tmp) < 0) strippedFileName = g_strdup(tmp);
goto cleanup;
tmp = strippedFileName; tmp = strippedFileName;
@ -199,8 +198,7 @@ esxParseVMXFileName(const char *fileName, void *opaque)
/* Fallback to direct datastore name match */ /* Fallback to direct datastore name match */
if (!result && STRPREFIX(fileName, "/vmfs/volumes/")) { if (!result && STRPREFIX(fileName, "/vmfs/volumes/")) {
if (VIR_STRDUP(copyOfFileName, fileName) < 0) copyOfFileName = g_strdup(fileName);
goto cleanup;
/* Expected format: '/vmfs/volumes/<datastore>/<path>' */ /* Expected format: '/vmfs/volumes/<datastore>/<path>' */
if (!(tmp = STRSKIP(copyOfFileName, "/vmfs/volumes/")) || if (!(tmp = STRSKIP(copyOfFileName, "/vmfs/volumes/")) ||
@ -235,8 +233,7 @@ esxParseVMXFileName(const char *fileName, void *opaque)
/* If it's an absolute path outside of a datastore just use it as is */ /* If it's an absolute path outside of a datastore just use it as is */
if (!result && *fileName == '/') { if (!result && *fileName == '/') {
/* FIXME: need to deal with Windows paths here too */ /* FIXME: need to deal with Windows paths here too */
if (VIR_STRDUP(result, fileName) < 0) result = g_strdup(fileName);
goto cleanup;
} }
if (!result) { if (!result) {
@ -334,8 +331,7 @@ esxFormatVMXFileName(const char *fileName, void *opaque)
result = virBufferContentAndReset(&buffer); result = virBufferContentAndReset(&buffer);
} else if (*fileName == '/') { } else if (*fileName == '/') {
/* FIXME: need to deal with Windows paths here too */ /* FIXME: need to deal with Windows paths here too */
if (VIR_STRDUP(result, fileName) < 0) result = g_strdup(fileName);
goto cleanup;
} else { } else {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("Could not handle file name '%s'"), fileName); _("Could not handle file name '%s'"), fileName);
@ -632,8 +628,7 @@ esxConnectToHost(esxPrivate *priv,
return -1; return -1;
if (conn->uri->user) { if (conn->uri->user) {
if (VIR_STRDUP(username, conn->uri->user) < 0) username = g_strdup(conn->uri->user);
goto cleanup;
} else { } else {
if (!(username = virAuthGetUsername(conn, auth, "esx", "root", if (!(username = virAuthGetUsername(conn, auth, "esx", "root",
conn->uri->server))) conn->uri->server)))
@ -683,8 +678,7 @@ esxConnectToHost(esxPrivate *priv,
if (inMaintenanceMode == esxVI_Boolean_True) if (inMaintenanceMode == esxVI_Boolean_True)
VIR_WARN("The server is in maintenance mode"); VIR_WARN("The server is in maintenance mode");
if (VIR_STRDUP(*vCenterIPAddress, *vCenterIPAddress) < 0) *vCenterIPAddress = g_strdup(*vCenterIPAddress);
goto cleanup;
result = 0; result = 0;
@ -724,8 +718,7 @@ esxConnectToVCenter(esxPrivate *priv,
return -1; return -1;
if (conn->uri->user) { if (conn->uri->user) {
if (VIR_STRDUP(username, conn->uri->user) < 0) username = g_strdup(conn->uri->user);
goto cleanup;
} else { } else {
if (!(username = virAuthGetUsername(conn, auth, "esx", "administrator", if (!(username = virAuthGetUsername(conn, auth, "esx", "administrator",
hostname))) hostname)))
@ -1169,19 +1162,13 @@ esxConnectGetHostname(virConnectPtr conn)
} }
if (!domainName || strlen(domainName) < 1) { if (!domainName || strlen(domainName) < 1) {
if (VIR_STRDUP(complete, hostName) < 0) complete = g_strdup(hostName);
goto cleanup;
} else { } else {
if (virAsprintf(&complete, "%s.%s", hostName, domainName) < 0) if (virAsprintf(&complete, "%s.%s", hostName, domainName) < 0)
goto cleanup; goto cleanup;
} }
cleanup: cleanup:
/*
* If we goto cleanup in case of an error then complete is still NULL,
* either VIR_STRDUP returned -1 or virAsprintf failed. When virAsprintf
* fails it guarantees setting complete to NULL
*/
esxVI_String_Free(&propertyNameList); esxVI_String_Free(&propertyNameList);
esxVI_ObjectContent_Free(&hostSystem); esxVI_ObjectContent_Free(&hostSystem);
@ -2431,8 +2418,7 @@ esxDomainScreenshot(virDomainPtr domain, virStreamPtr stream,
url = virBufferContentAndReset(&buffer); url = virBufferContentAndReset(&buffer);
if (VIR_STRDUP(mimeType, "image/png") < 0) mimeType = g_strdup("image/png");
goto cleanup;
if (esxStreamOpenDownload(stream, priv, url, 0, 0) < 0) { if (esxStreamOpenDownload(stream, priv, url, 0, 0) < 0) {
VIR_FREE(mimeType); VIR_FREE(mimeType);
@ -3454,8 +3440,7 @@ esxDomainGetSchedulerType(virDomainPtr domain G_GNUC_UNUSED, int *nparams)
{ {
char *type; char *type;
if (VIR_STRDUP(type, "allocation") < 0) type = g_strdup("allocation");
return NULL;
if (nparams) if (nparams)
*nparams = 3; /* reservation, limit, shares */ *nparams = 3; /* reservation, limit, shares */

View File

@ -66,12 +66,10 @@ esxConnectNumOfInterfaces(virConnectPtr conn)
static int static int
esxConnectListInterfaces(virConnectPtr conn, char **const names, int maxnames) esxConnectListInterfaces(virConnectPtr conn, char **const names, int maxnames)
{ {
bool success = false;
esxPrivate *priv = conn->privateData; esxPrivate *priv = conn->privateData;
esxVI_PhysicalNic *physicalNicList = NULL; esxVI_PhysicalNic *physicalNicList = NULL;
esxVI_PhysicalNic *physicalNic = NULL; esxVI_PhysicalNic *physicalNic = NULL;
int count = 0; int count = 0;
size_t i;
if (maxnames == 0) if (maxnames == 0)
return 0; return 0;
@ -83,22 +81,11 @@ esxConnectListInterfaces(virConnectPtr conn, char **const names, int maxnames)
for (physicalNic = physicalNicList; physicalNic; for (physicalNic = physicalNicList; physicalNic;
physicalNic = physicalNic->_next) { physicalNic = physicalNic->_next) {
if (VIR_STRDUP(names[count], physicalNic->device) < 0) names[count] = g_strdup(physicalNic->device);
goto cleanup;
++count; ++count;
} }
success = true;
cleanup:
if (! success) {
for (i = 0; i < count; ++i)
VIR_FREE(names[i]);
count = -1;
}
esxVI_PhysicalNic_Free(&physicalNicList); esxVI_PhysicalNic_Free(&physicalNicList);
return count; return count;

View File

@ -73,12 +73,10 @@ esxConnectNumOfNetworks(virConnectPtr conn)
static int static int
esxConnectListNetworks(virConnectPtr conn, char **const names, int maxnames) esxConnectListNetworks(virConnectPtr conn, char **const names, int maxnames)
{ {
bool success = false;
esxPrivate *priv = conn->privateData; esxPrivate *priv = conn->privateData;
esxVI_HostVirtualSwitch *hostVirtualSwitchList = NULL; esxVI_HostVirtualSwitch *hostVirtualSwitchList = NULL;
esxVI_HostVirtualSwitch *hostVirtualSwitch = NULL; esxVI_HostVirtualSwitch *hostVirtualSwitch = NULL;
int count = 0; int count = 0;
size_t i;
if (maxnames == 0) if (maxnames == 0)
return 0; return 0;
@ -91,22 +89,11 @@ esxConnectListNetworks(virConnectPtr conn, char **const names, int maxnames)
for (hostVirtualSwitch = hostVirtualSwitchList; hostVirtualSwitch; for (hostVirtualSwitch = hostVirtualSwitchList; hostVirtualSwitch;
hostVirtualSwitch = hostVirtualSwitch->_next) { hostVirtualSwitch = hostVirtualSwitch->_next) {
if (VIR_STRDUP(names[count], hostVirtualSwitch->name) < 0) names[count] = g_strdup(hostVirtualSwitch->name);
goto cleanup;
++count; ++count;
} }
success = true;
cleanup:
if (! success) {
for (i = 0; i < count; ++i)
VIR_FREE(names[i]);
count = -1;
}
esxVI_HostVirtualSwitch_Free(&hostVirtualSwitchList); esxVI_HostVirtualSwitch_Free(&hostVirtualSwitchList);
return count; return count;
@ -447,12 +434,13 @@ esxNetworkDefineXML(virConnectPtr conn, const char *xml)
if (esxVI_HostPortGroupSpec_Alloc(&hostPortGroupSpec) < 0 || if (esxVI_HostPortGroupSpec_Alloc(&hostPortGroupSpec) < 0 ||
esxVI_HostNetworkPolicy_Alloc(&hostPortGroupSpec->policy) < 0 || esxVI_HostNetworkPolicy_Alloc(&hostPortGroupSpec->policy) < 0 ||
esxVI_Int_Alloc(&hostPortGroupSpec->vlanId) < 0 || esxVI_Int_Alloc(&hostPortGroupSpec->vlanId) < 0) {
VIR_STRDUP(hostPortGroupSpec->name, def->portGroups[i].name) < 0 ||
VIR_STRDUP(hostPortGroupSpec->vswitchName, def->name) < 0) {
goto cleanup; goto cleanup;
} }
hostPortGroupSpec->name = g_strdup(def->portGroups[i].name);
hostPortGroupSpec->vswitchName = g_strdup(def->name);
hostPortGroupSpec->vlanId->value = 0; hostPortGroupSpec->vlanId->value = 0;
if (def->portGroups[i].bandwidth) { if (def->portGroups[i].bandwidth) {
@ -670,8 +658,7 @@ esxNetworkGetXMLDesc(virNetworkPtr network_, unsigned int flags)
if (virCryptoHashBuf(VIR_CRYPTO_HASH_MD5, hostVirtualSwitch->key, def->uuid) < 0) if (virCryptoHashBuf(VIR_CRYPTO_HASH_MD5, hostVirtualSwitch->key, def->uuid) < 0)
goto cleanup; goto cleanup;
if (VIR_STRDUP(def->name, hostVirtualSwitch->name) < 0) def->name = g_strdup(hostVirtualSwitch->name);
goto cleanup;
def->forward.type = VIR_NETWORK_FORWARD_NONE; def->forward.type = VIR_NETWORK_FORWARD_NONE;
@ -702,9 +689,7 @@ esxNetworkGetXMLDesc(virNetworkPtr network_, unsigned int flags)
if (STREQ(physicalNicKey->value, physicalNic->key)) { if (STREQ(physicalNicKey->value, physicalNic->key)) {
def->forward.ifs[def->forward.nifs].type def->forward.ifs[def->forward.nifs].type
= VIR_NETWORK_FORWARD_HOSTDEV_DEVICE_NETDEV; = VIR_NETWORK_FORWARD_HOSTDEV_DEVICE_NETDEV;
if (VIR_STRDUP(def->forward.ifs[def->forward.nifs].device.dev, def->forward.ifs[def->forward.nifs].device.dev = g_strdup(physicalNic->device);
physicalNic->device) < 0)
goto cleanup;
++def->forward.nifs; ++def->forward.nifs;
@ -766,9 +751,7 @@ esxNetworkGetXMLDesc(virNetworkPtr network_, unsigned int flags)
for (networkName = networkNameList; networkName; for (networkName = networkNameList; networkName;
networkName = networkName->_next) { networkName = networkName->_next) {
if (STREQ(networkName->value, hostPortGroup->spec->name)) { if (STREQ(networkName->value, hostPortGroup->spec->name)) {
if (VIR_STRDUP(def->portGroups[def->nPortGroups].name, def->portGroups[def->nPortGroups].name = g_strdup(networkName->value);
networkName->value) < 0)
goto cleanup;
if (hostPortGroup->spec->policy) { if (hostPortGroup->spec->policy) {
if (esxShapingPolicyToBandwidth if (esxShapingPolicyToBandwidth

View File

@ -127,8 +127,7 @@ esxConnectListStoragePools(virConnectPtr conn, char **const names,
*/ */
for (target = hostInternetScsiHba->configuredStaticTarget; for (target = hostInternetScsiHba->configuredStaticTarget;
target && count < maxnames; target = target->_next) { target && count < maxnames; target = target->_next) {
if (VIR_STRDUP(names[count], target->iScsiName) < 0) names[count] = g_strdup(target->iScsiName);
goto cleanup;
++count; ++count;
} }
@ -406,8 +405,7 @@ esxStoragePoolListVolumes(virStoragePoolPtr pool, char **const names,
hostScsiTopologyLun && count < maxnames; hostScsiTopologyLun && count < maxnames;
hostScsiTopologyLun = hostScsiTopologyLun->_next) { hostScsiTopologyLun = hostScsiTopologyLun->_next) {
if (STREQ(hostScsiTopologyLun->scsiLun, scsiLun->key)) { if (STREQ(hostScsiTopologyLun->scsiLun, scsiLun->key)) {
if (VIR_STRDUP(names[count], scsiLun->deviceName) < 0) names[count] = g_strdup(scsiLun->deviceName);
goto cleanup;
++count; ++count;
} }
@ -705,8 +703,7 @@ esxStorageVolGetXMLDesc(virStorageVolPtr volume,
virUUIDFormat(md5, uuid_string); virUUIDFormat(md5, uuid_string);
if (VIR_STRDUP(def.key, uuid_string) < 0) def.key = g_strdup(uuid_string);
goto cleanup;
/* iSCSI LUN exposes a block device */ /* iSCSI LUN exposes a block device */
def.type = VIR_STORAGE_VOL_BLOCK; def.type = VIR_STORAGE_VOL_BLOCK;

View File

@ -166,8 +166,7 @@ esxConnectListStoragePools(virConnectPtr conn, char **const names,
goto cleanup; goto cleanup;
} }
if (VIR_STRDUP(names[count], dynamicProperty->val->string) < 0) names[count] = g_strdup(dynamicProperty->val->string);
goto cleanup;
++count; ++count;
break; break;
@ -605,8 +604,7 @@ esxStoragePoolListVolumes(virStoragePoolPtr pool, char **const names,
for (fileInfo = searchResults->file; fileInfo; for (fileInfo = searchResults->file; fileInfo;
fileInfo = fileInfo->_next) { fileInfo = fileInfo->_next) {
if (length < 1) { if (length < 1) {
if (VIR_STRDUP(names[count], fileInfo->path) < 0) names[count] = g_strdup(fileInfo->path);
goto cleanup;
} else if (virAsprintf(&names[count], "%s/%s", directoryAndFileName, } else if (virAsprintf(&names[count], "%s/%s", directoryAndFileName,
fileInfo->path) < 0) { fileInfo->path) < 0) {
goto cleanup; goto cleanup;
@ -774,8 +772,7 @@ esxStorageVolLookupByKey(virConnectPtr conn, const char *key)
VIR_FREE(datastorePath); VIR_FREE(datastorePath);
if (length < 1) { if (length < 1) {
if (VIR_STRDUP(volumeName, fileInfo->path) < 0) volumeName = g_strdup(fileInfo->path);
goto cleanup;
} else if (virAsprintf(&volumeName, "%s/%s", } else if (virAsprintf(&volumeName, "%s/%s",
directoryAndFileName, directoryAndFileName,
fileInfo->path) < 0) { fileInfo->path) < 0) {
@ -1005,8 +1002,7 @@ esxStorageVolCreateXML(virStoragePoolPtr pool,
goto cleanup; goto cleanup;
} else { } else {
/* Fall back to the path as key */ /* Fall back to the path as key */
if (VIR_STRDUP(key, datastorePath) < 0) key = g_strdup(datastorePath);
goto cleanup;
} }
} else { } else {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
@ -1191,8 +1187,7 @@ esxStorageVolCreateXMLFrom(virStoragePoolPtr pool,
goto cleanup; goto cleanup;
} else { } else {
/* Fall back to the path as key */ /* Fall back to the path as key */
if (VIR_STRDUP(key, datastorePath) < 0) key = g_strdup(datastorePath);
goto cleanup;
} }
} else { } else {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,

View File

@ -59,8 +59,7 @@ esxUtil_ParseUri(esxUtil_ParsedUri **parsedUri, virURIPtr uri)
if (STRCASEEQ(queryParam->name, "transport")) { if (STRCASEEQ(queryParam->name, "transport")) {
VIR_FREE((*parsedUri)->transport); VIR_FREE((*parsedUri)->transport);
if (VIR_STRDUP((*parsedUri)->transport, queryParam->value) < 0) (*parsedUri)->transport = g_strdup(queryParam->value);
goto cleanup;
if (STRNEQ((*parsedUri)->transport, "http") && if (STRNEQ((*parsedUri)->transport, "http") &&
STRNEQ((*parsedUri)->transport, "https")) { STRNEQ((*parsedUri)->transport, "https")) {
@ -73,8 +72,7 @@ esxUtil_ParseUri(esxUtil_ParsedUri **parsedUri, virURIPtr uri)
} else if (STRCASEEQ(queryParam->name, "vcenter")) { } else if (STRCASEEQ(queryParam->name, "vcenter")) {
VIR_FREE((*parsedUri)->vCenter); VIR_FREE((*parsedUri)->vCenter);
if (VIR_STRDUP((*parsedUri)->vCenter, queryParam->value) < 0) (*parsedUri)->vCenter = g_strdup(queryParam->value);
goto cleanup;
} else if (STRCASEEQ(queryParam->name, "no_verify")) { } else if (STRCASEEQ(queryParam->name, "no_verify")) {
if (virStrToLong_i(queryParam->value, NULL, 10, &noVerify) < 0 || if (virStrToLong_i(queryParam->value, NULL, 10, &noVerify) < 0 ||
(noVerify != 0 && noVerify != 1)) { (noVerify != 0 && noVerify != 1)) {
@ -123,8 +121,7 @@ esxUtil_ParseUri(esxUtil_ParsedUri **parsedUri, virURIPtr uri)
tmp = queryParam->value; tmp = queryParam->value;
} }
if (VIR_STRDUP((*parsedUri)->proxy_hostname, tmp) < 0) (*parsedUri)->proxy_hostname = g_strdup(tmp);
goto cleanup;
if ((tmp = strchr((*parsedUri)->proxy_hostname, ':'))) { if ((tmp = strchr((*parsedUri)->proxy_hostname, ':'))) {
if (tmp == (*parsedUri)->proxy_hostname) { if (tmp == (*parsedUri)->proxy_hostname) {
@ -153,8 +150,7 @@ esxUtil_ParseUri(esxUtil_ParsedUri **parsedUri, virURIPtr uri)
} }
} }
if (VIR_STRDUP((*parsedUri)->path, uri->path) < 0) (*parsedUri)->path = g_strdup(uri->path);
goto cleanup;
if (!(*parsedUri)->transport) if (!(*parsedUri)->transport)
(*parsedUri)->transport = g_strdup("https"); (*parsedUri)->transport = g_strdup("https");
@ -226,8 +222,7 @@ esxUtil_ParseDatastorePath(const char *datastorePath, char **datastoreName,
return -1; return -1;
} }
if (VIR_STRDUP(copyOfDatastorePath, datastorePath) < 0) copyOfDatastorePath = g_strdup(datastorePath);
goto cleanup;
/* Expected format: '[<datastore>] <path>' where <path> is optional */ /* Expected format: '[<datastore>] <path>' where <path> is optional */
if (!(tmp = STRSKIP(copyOfDatastorePath, "[")) || *tmp == ']' || if (!(tmp = STRSKIP(copyOfDatastorePath, "[")) || *tmp == ']' ||
@ -238,10 +233,8 @@ esxUtil_ParseDatastorePath(const char *datastorePath, char **datastoreName,
goto cleanup; goto cleanup;
} }
if (datastoreName && if (datastoreName)
VIR_STRDUP(*datastoreName, preliminaryDatastoreName) < 0) { *datastoreName = g_strdup(preliminaryDatastoreName);
goto cleanup;
}
preliminaryDirectoryAndFileName = strtok_r(NULL, "", &saveptr); preliminaryDirectoryAndFileName = strtok_r(NULL, "", &saveptr);
@ -252,10 +245,8 @@ esxUtil_ParseDatastorePath(const char *datastorePath, char **datastoreName,
strspn(preliminaryDirectoryAndFileName, " "); strspn(preliminaryDirectoryAndFileName, " ");
} }
if (directoryAndFileName && if (directoryAndFileName)
VIR_STRDUP(*directoryAndFileName, preliminaryDirectoryAndFileName) < 0) { *directoryAndFileName = g_strdup(preliminaryDirectoryAndFileName);
goto cleanup;
}
if (directoryName) { if (directoryName) {
/* Split <path> into <directory>/<file> and remove /<file> */ /* Split <path> into <directory>/<file> and remove /<file> */
@ -264,8 +255,7 @@ esxUtil_ParseDatastorePath(const char *datastorePath, char **datastoreName,
if (tmp) if (tmp)
*tmp = '\0'; *tmp = '\0';
if (VIR_STRDUP(*directoryName, preliminaryDirectoryAndFileName) < 0) *directoryName = g_strdup(preliminaryDirectoryAndFileName);
goto cleanup;
} }
result = 0; result = 0;
@ -447,8 +437,7 @@ esxUtil_EscapeDatastoreItem(const char *string)
char *escaped1; char *escaped1;
char *escaped2 = NULL; char *escaped2 = NULL;
if (VIR_STRDUP(replaced, string) < 0) replaced = g_strdup(string);
return NULL;
esxUtil_ReplaceSpecialWindowsPathChars(replaced); esxUtil_ReplaceSpecialWindowsPathChars(replaced);

View File

@ -1012,14 +1012,15 @@ esxVI_Context_Connect(esxVI_Context *ctx, const char *url,
} }
if (esxVI_CURL_Alloc(&ctx->curl) < 0 || if (esxVI_CURL_Alloc(&ctx->curl) < 0 ||
esxVI_CURL_Connect(ctx->curl, parsedUri) < 0 || esxVI_CURL_Connect(ctx->curl, parsedUri) < 0) {
VIR_STRDUP(ctx->url, url) < 0 ||
VIR_STRDUP(ctx->ipAddress, ipAddress) < 0 ||
VIR_STRDUP(ctx->username, username) < 0 ||
VIR_STRDUP(ctx->password, password) < 0) {
goto cleanup; goto cleanup;
} }
ctx->url = g_strdup(url);
ctx->ipAddress = g_strdup(ipAddress);
ctx->username = g_strdup(username);
ctx->password = g_strdup(password);
if (VIR_ALLOC(ctx->sessionLock) < 0) if (VIR_ALLOC(ctx->sessionLock) < 0)
goto cleanup; goto cleanup;
@ -1142,8 +1143,7 @@ esxVI_Context_LookupManagedObjects(esxVI_Context *ctx)
return -1; return -1;
} }
if (VIR_STRDUP(ctx->datacenterPath, ctx->datacenter->name) < 0) ctx->datacenterPath = g_strdup(ctx->datacenter->name);
return -1;
/* Lookup (Cluster)ComputeResource */ /* Lookup (Cluster)ComputeResource */
if (esxVI_LookupComputeResource(ctx, NULL, ctx->datacenter->hostFolder, if (esxVI_LookupComputeResource(ctx, NULL, ctx->datacenter->hostFolder,
@ -1158,8 +1158,7 @@ esxVI_Context_LookupManagedObjects(esxVI_Context *ctx)
return -1; return -1;
} }
if (VIR_STRDUP(ctx->computeResourcePath, ctx->computeResource->name) < 0) ctx->computeResourcePath = g_strdup(ctx->computeResource->name);
return -1;
/* Lookup HostSystem */ /* Lookup HostSystem */
if (esxVI_LookupHostSystem(ctx, NULL, ctx->computeResource->_reference, if (esxVI_LookupHostSystem(ctx, NULL, ctx->computeResource->_reference,
@ -1168,8 +1167,7 @@ esxVI_Context_LookupManagedObjects(esxVI_Context *ctx)
return -1; return -1;
} }
if (VIR_STRDUP(ctx->hostSystemName, ctx->hostSystem->name) < 0) ctx->hostSystemName = g_strdup(ctx->hostSystem->name);
return -1;
return 0; return 0;
} }
@ -1186,8 +1184,7 @@ esxVI_Context_LookupManagedObjectsByPath(esxVI_Context *ctx, const char *path)
esxVI_ManagedObjectReference *root = NULL; esxVI_ManagedObjectReference *root = NULL;
esxVI_Folder *folder = NULL; esxVI_Folder *folder = NULL;
if (VIR_STRDUP(tmp, path) < 0) tmp = g_strdup(path);
goto cleanup;
/* Lookup Datacenter */ /* Lookup Datacenter */
item = strtok_r(tmp, "/", &saveptr); item = strtok_r(tmp, "/", &saveptr);
@ -1330,8 +1327,7 @@ esxVI_Context_LookupManagedObjectsByPath(esxVI_Context *ctx, const char *path)
goto cleanup; goto cleanup;
} }
if (VIR_STRDUP(ctx->hostSystemName, previousItem) < 0) ctx->hostSystemName = g_strdup(previousItem);
goto cleanup;
if (esxVI_LookupHostSystem(ctx, ctx->hostSystemName, if (esxVI_LookupHostSystem(ctx, ctx->hostSystemName,
ctx->computeResource->_reference, NULL, ctx->computeResource->_reference, NULL,
@ -1927,25 +1923,26 @@ esxVI_BuildSelectSet(esxVI_SelectionSpec **selectSet,
return -1; return -1;
} }
if (esxVI_TraversalSpec_Alloc(&traversalSpec) < 0 || if (esxVI_TraversalSpec_Alloc(&traversalSpec) < 0)
VIR_STRDUP(traversalSpec->name, name) < 0 ||
VIR_STRDUP(traversalSpec->type, type) < 0 ||
VIR_STRDUP(traversalSpec->path, path) < 0) {
goto failure; goto failure;
}
traversalSpec->name = g_strdup(name);
traversalSpec->type = g_strdup(type);
traversalSpec->path = g_strdup(path);
traversalSpec->skip = esxVI_Boolean_False; traversalSpec->skip = esxVI_Boolean_False;
if (selectSetNames) { if (selectSetNames) {
currentSelectSetName = selectSetNames; currentSelectSetName = selectSetNames;
while (currentSelectSetName && *currentSelectSetName != '\0') { while (currentSelectSetName && *currentSelectSetName != '\0') {
if (esxVI_SelectionSpec_Alloc(&selectionSpec) < 0 || if (esxVI_SelectionSpec_Alloc(&selectionSpec) < 0)
VIR_STRDUP(selectionSpec->name, currentSelectSetName) < 0 || goto failure;
esxVI_SelectionSpec_AppendToList(&traversalSpec->selectSet,
selectionSpec) < 0) { selectionSpec->name = g_strdup(currentSelectSetName);
if (esxVI_SelectionSpec_AppendToList(&traversalSpec->selectSet,
selectionSpec) < 0)
goto failure; goto failure;
}
selectionSpec = NULL; selectionSpec = NULL;
currentSelectSetName += strlen(currentSelectSetName) + 1; currentSelectSetName += strlen(currentSelectSetName) + 1;
@ -2646,8 +2643,7 @@ esxVI_GetVirtualMachineIdentity(esxVI_ObjectContent *virtualMachine,
goto failure; goto failure;
} }
if (VIR_STRDUP(*name, dynamicProperty->val->string) < 0) *name = g_strdup(dynamicProperty->val->string);
goto failure;
if (virVMXUnescapeHexPercent(*name) < 0) { if (virVMXUnescapeHexPercent(*name) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
@ -2754,8 +2750,7 @@ esxVI_GetSnapshotTreeNames(esxVI_VirtualMachineSnapshotTree *snapshotTreeList,
snapshotTree && count < nameslen; snapshotTree && count < nameslen;
snapshotTree = snapshotTree->_next) { snapshotTree = snapshotTree->_next) {
if (!(leaves && snapshotTree->childSnapshotList)) { if (!(leaves && snapshotTree->childSnapshotList)) {
if (VIR_STRDUP(names[count], snapshotTree->name) < 0) names[count] = g_strdup(snapshotTree->name);
goto failure;
count++; count++;
} }
@ -3597,8 +3592,7 @@ esxVI_LookupFileInfoByDatastorePath(esxVI_Context *ctx,
datastoreName) < 0) datastoreName) < 0)
goto cleanup; goto cleanup;
if (VIR_STRDUP(fileName, directoryAndFileName) < 0) fileName = g_strdup(directoryAndFileName);
goto cleanup;
} else { } else {
if (virAsprintf(&datastorePathWithoutFileName, "[%s] %s", if (virAsprintf(&datastorePathWithoutFileName, "[%s] %s",
datastoreName, directoryName) < 0) datastoreName, directoryName) < 0)
@ -3614,8 +3608,7 @@ esxVI_LookupFileInfoByDatastorePath(esxVI_Context *ctx,
goto cleanup; goto cleanup;
} }
if (VIR_STRDUP(fileName, directoryAndFileName + length + 1) < 0) fileName = g_strdup(directoryAndFileName + length + 1);
goto cleanup;
} }
/* Lookup HostDatastoreBrowser */ /* Lookup HostDatastoreBrowser */
@ -3910,8 +3903,7 @@ esxVI_LookupStorageVolumeKeyByDatastorePath(esxVI_Context *ctx,
if (!(*key)) { if (!(*key)) {
/* Other files don't have a UUID, fall back to the path as key */ /* Other files don't have a UUID, fall back to the path as key */
if (VIR_STRDUP(*key, datastorePath) < 0) *key = g_strdup(datastorePath);
goto cleanup;
} }
result = 0; result = 0;
@ -4430,8 +4422,7 @@ esxVI_WaitForTaskCompletion(esxVI_Context *ctx,
ESX_VI_CHECK_ARG_LIST(errorMessage); ESX_VI_CHECK_ARG_LIST(errorMessage);
if (VIR_STRDUP(version, "") < 0) version = g_strdup("");
return -1;
if (esxVI_ObjectSpec_Alloc(&objectSpec) < 0) if (esxVI_ObjectSpec_Alloc(&objectSpec) < 0)
goto cleanup; goto cleanup;
@ -4503,8 +4494,7 @@ esxVI_WaitForTaskCompletion(esxVI_Context *ctx,
goto cleanup; goto cleanup;
VIR_FREE(version); VIR_FREE(version);
if (VIR_STRDUP(version, updateSet->version) < 0) version = g_strdup(updateSet->version);
goto cleanup;
if (!updateSet->filterSet) if (!updateSet->filterSet)
continue; continue;
@ -4547,11 +4537,9 @@ esxVI_WaitForTaskCompletion(esxVI_Context *ctx,
goto cleanup; goto cleanup;
if (!taskInfo->error) { if (!taskInfo->error) {
if (VIR_STRDUP(*errorMessage, _("Unknown error")) < 0) *errorMessage = g_strdup(_("Unknown error"));
goto cleanup;
} else if (!taskInfo->error->localizedMessage) { } else if (!taskInfo->error->localizedMessage) {
if (VIR_STRDUP(*errorMessage, taskInfo->error->fault->_actualType) < 0) *errorMessage = g_strdup(taskInfo->error->fault->_actualType);
goto cleanup;
} else { } else {
if (virAsprintf(errorMessage, "%s - %s", if (virAsprintf(errorMessage, "%s - %s",
taskInfo->error->fault->_actualType, taskInfo->error->fault->_actualType,
@ -5032,9 +5020,8 @@ esxVI_LookupStoragePoolNameByScsiLunKey(esxVI_Context *ctx,
for (hostScsiTopologyLun = hostScsiTopologyTarget->lun; for (hostScsiTopologyLun = hostScsiTopologyTarget->lun;
hostScsiTopologyLun; hostScsiTopologyLun;
hostScsiTopologyLun = hostScsiTopologyLun->_next) { hostScsiTopologyLun = hostScsiTopologyLun->_next) {
if (STREQ(hostScsiTopologyLun->scsiLun, key) && if (STREQ(hostScsiTopologyLun->scsiLun, key))
VIR_STRDUP(*poolName, candidate->iScsiName) < 0) *poolName = g_strdup(candidate->iScsiName);
goto cleanup;
} }
/* hostScsiTopologyLun iteration done, terminate loop */ /* hostScsiTopologyLun iteration done, terminate loop */

View File

@ -951,10 +951,8 @@ esxVI_AnyType_DeepCopy(esxVI_AnyType **dest, esxVI_AnyType *src)
(*dest)->type = src->type; (*dest)->type = src->type;
if (VIR_STRDUP((*dest)->other, src->other) < 0 || (*dest)->other = g_strdup(src->other);
VIR_STRDUP((*dest)->value, src->value) < 0) { (*dest)->value = g_strdup(src->value);
goto failure;
}
switch ((int)src->type) { switch ((int)src->type) {
case esxVI_Type_Boolean: case esxVI_Type_Boolean:
@ -1153,8 +1151,7 @@ esxVI_String_AppendValueToList(esxVI_String **stringList, const char *value)
if (esxVI_String_Alloc(&string) < 0) if (esxVI_String_Alloc(&string) < 0)
return -1; return -1;
if (VIR_STRDUP(string->value, value) < 0) string->value = g_strdup(value);
goto failure;
if (esxVI_String_AppendToList(stringList, string) < 0) if (esxVI_String_AppendToList(stringList, string) < 0)
goto failure; goto failure;
@ -1275,8 +1272,10 @@ esxVI_String_DeserializeValue(xmlNodePtr node, char **value)
ESX_VI_CHECK_ARG_LIST(value); ESX_VI_CHECK_ARG_LIST(value);
*value = (char *)xmlNodeListGetString(node->doc, node->children, 1); *value = (char *)xmlNodeListGetString(node->doc, node->children, 1);
if (!*value)
*value = g_strdup("");
return *value ? 0 : VIR_STRDUP(*value, ""); return 0;
} }