while (*tmp == '/' || *tmp == '\\')
++tmp;
- if (VIR_STRDUP(strippedFileName, tmp) < 0)
- goto cleanup;
+ strippedFileName = g_strdup(tmp);
tmp = strippedFileName;
/* Fallback to direct datastore name match */
if (!result && STRPREFIX(fileName, "/vmfs/volumes/")) {
- if (VIR_STRDUP(copyOfFileName, fileName) < 0)
- goto cleanup;
+ copyOfFileName = g_strdup(fileName);
/* Expected format: '/vmfs/volumes/<datastore>/<path>' */
if (!(tmp = STRSKIP(copyOfFileName, "/vmfs/volumes/")) ||
/* If it's an absolute path outside of a datastore just use it as is */
if (!result && *fileName == '/') {
/* FIXME: need to deal with Windows paths here too */
- if (VIR_STRDUP(result, fileName) < 0)
- goto cleanup;
+ result = g_strdup(fileName);
}
if (!result) {
result = virBufferContentAndReset(&buffer);
} else if (*fileName == '/') {
/* FIXME: need to deal with Windows paths here too */
- if (VIR_STRDUP(result, fileName) < 0)
- goto cleanup;
+ result = g_strdup(fileName);
} else {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Could not handle file name '%s'"), fileName);
return -1;
if (conn->uri->user) {
- if (VIR_STRDUP(username, conn->uri->user) < 0)
- goto cleanup;
+ username = g_strdup(conn->uri->user);
} else {
if (!(username = virAuthGetUsername(conn, auth, "esx", "root",
conn->uri->server)))
if (inMaintenanceMode == esxVI_Boolean_True)
VIR_WARN("The server is in maintenance mode");
- if (VIR_STRDUP(*vCenterIPAddress, *vCenterIPAddress) < 0)
- goto cleanup;
+ *vCenterIPAddress = g_strdup(*vCenterIPAddress);
result = 0;
return -1;
if (conn->uri->user) {
- if (VIR_STRDUP(username, conn->uri->user) < 0)
- goto cleanup;
+ username = g_strdup(conn->uri->user);
} else {
if (!(username = virAuthGetUsername(conn, auth, "esx", "administrator",
hostname)))
}
if (!domainName || strlen(domainName) < 1) {
- if (VIR_STRDUP(complete, hostName) < 0)
- goto cleanup;
+ complete = g_strdup(hostName);
} else {
if (virAsprintf(&complete, "%s.%s", hostName, domainName) < 0)
goto 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_ObjectContent_Free(&hostSystem);
url = virBufferContentAndReset(&buffer);
- if (VIR_STRDUP(mimeType, "image/png") < 0)
- goto cleanup;
+ mimeType = g_strdup("image/png");
if (esxStreamOpenDownload(stream, priv, url, 0, 0) < 0) {
VIR_FREE(mimeType);
{
char *type;
- if (VIR_STRDUP(type, "allocation") < 0)
- return NULL;
+ type = g_strdup("allocation");
if (nparams)
*nparams = 3; /* reservation, limit, shares */
static int
esxConnectListInterfaces(virConnectPtr conn, char **const names, int maxnames)
{
- bool success = false;
esxPrivate *priv = conn->privateData;
esxVI_PhysicalNic *physicalNicList = NULL;
esxVI_PhysicalNic *physicalNic = NULL;
int count = 0;
- size_t i;
if (maxnames == 0)
return 0;
for (physicalNic = physicalNicList; physicalNic;
physicalNic = physicalNic->_next) {
- if (VIR_STRDUP(names[count], physicalNic->device) < 0)
- goto cleanup;
+ names[count] = g_strdup(physicalNic->device);
++count;
}
- success = true;
-
- cleanup:
- if (! success) {
- for (i = 0; i < count; ++i)
- VIR_FREE(names[i]);
-
- count = -1;
- }
-
esxVI_PhysicalNic_Free(&physicalNicList);
return count;
static int
esxConnectListNetworks(virConnectPtr conn, char **const names, int maxnames)
{
- bool success = false;
esxPrivate *priv = conn->privateData;
esxVI_HostVirtualSwitch *hostVirtualSwitchList = NULL;
esxVI_HostVirtualSwitch *hostVirtualSwitch = NULL;
int count = 0;
- size_t i;
if (maxnames == 0)
return 0;
for (hostVirtualSwitch = hostVirtualSwitchList; hostVirtualSwitch;
hostVirtualSwitch = hostVirtualSwitch->_next) {
- if (VIR_STRDUP(names[count], hostVirtualSwitch->name) < 0)
- goto cleanup;
+ names[count] = g_strdup(hostVirtualSwitch->name);
++count;
}
- success = true;
-
- cleanup:
- if (! success) {
- for (i = 0; i < count; ++i)
- VIR_FREE(names[i]);
-
- count = -1;
- }
-
esxVI_HostVirtualSwitch_Free(&hostVirtualSwitchList);
return count;
if (esxVI_HostPortGroupSpec_Alloc(&hostPortGroupSpec) < 0 ||
esxVI_HostNetworkPolicy_Alloc(&hostPortGroupSpec->policy) < 0 ||
- esxVI_Int_Alloc(&hostPortGroupSpec->vlanId) < 0 ||
- VIR_STRDUP(hostPortGroupSpec->name, def->portGroups[i].name) < 0 ||
- VIR_STRDUP(hostPortGroupSpec->vswitchName, def->name) < 0) {
+ esxVI_Int_Alloc(&hostPortGroupSpec->vlanId) < 0) {
goto cleanup;
}
+ hostPortGroupSpec->name = g_strdup(def->portGroups[i].name);
+ hostPortGroupSpec->vswitchName = g_strdup(def->name);
+
hostPortGroupSpec->vlanId->value = 0;
if (def->portGroups[i].bandwidth) {
if (virCryptoHashBuf(VIR_CRYPTO_HASH_MD5, hostVirtualSwitch->key, def->uuid) < 0)
goto cleanup;
- if (VIR_STRDUP(def->name, hostVirtualSwitch->name) < 0)
- goto cleanup;
+ def->name = g_strdup(hostVirtualSwitch->name);
def->forward.type = VIR_NETWORK_FORWARD_NONE;
if (STREQ(physicalNicKey->value, physicalNic->key)) {
def->forward.ifs[def->forward.nifs].type
= VIR_NETWORK_FORWARD_HOSTDEV_DEVICE_NETDEV;
- if (VIR_STRDUP(def->forward.ifs[def->forward.nifs].device.dev,
- physicalNic->device) < 0)
- goto cleanup;
+ def->forward.ifs[def->forward.nifs].device.dev = g_strdup(physicalNic->device);
++def->forward.nifs;
for (networkName = networkNameList; networkName;
networkName = networkName->_next) {
if (STREQ(networkName->value, hostPortGroup->spec->name)) {
- if (VIR_STRDUP(def->portGroups[def->nPortGroups].name,
- networkName->value) < 0)
- goto cleanup;
+ def->portGroups[def->nPortGroups].name = g_strdup(networkName->value);
if (hostPortGroup->spec->policy) {
if (esxShapingPolicyToBandwidth
*/
for (target = hostInternetScsiHba->configuredStaticTarget;
target && count < maxnames; target = target->_next) {
- if (VIR_STRDUP(names[count], target->iScsiName) < 0)
- goto cleanup;
+ names[count] = g_strdup(target->iScsiName);
++count;
}
hostScsiTopologyLun && count < maxnames;
hostScsiTopologyLun = hostScsiTopologyLun->_next) {
if (STREQ(hostScsiTopologyLun->scsiLun, scsiLun->key)) {
- if (VIR_STRDUP(names[count], scsiLun->deviceName) < 0)
- goto cleanup;
+ names[count] = g_strdup(scsiLun->deviceName);
++count;
}
virUUIDFormat(md5, uuid_string);
- if (VIR_STRDUP(def.key, uuid_string) < 0)
- goto cleanup;
+ def.key = g_strdup(uuid_string);
/* iSCSI LUN exposes a block device */
def.type = VIR_STORAGE_VOL_BLOCK;
goto cleanup;
}
- if (VIR_STRDUP(names[count], dynamicProperty->val->string) < 0)
- goto cleanup;
+ names[count] = g_strdup(dynamicProperty->val->string);
++count;
break;
for (fileInfo = searchResults->file; fileInfo;
fileInfo = fileInfo->_next) {
if (length < 1) {
- if (VIR_STRDUP(names[count], fileInfo->path) < 0)
- goto cleanup;
+ names[count] = g_strdup(fileInfo->path);
} else if (virAsprintf(&names[count], "%s/%s", directoryAndFileName,
fileInfo->path) < 0) {
goto cleanup;
VIR_FREE(datastorePath);
if (length < 1) {
- if (VIR_STRDUP(volumeName, fileInfo->path) < 0)
- goto cleanup;
+ volumeName = g_strdup(fileInfo->path);
} else if (virAsprintf(&volumeName, "%s/%s",
directoryAndFileName,
fileInfo->path) < 0) {
goto cleanup;
} else {
/* Fall back to the path as key */
- if (VIR_STRDUP(key, datastorePath) < 0)
- goto cleanup;
+ key = g_strdup(datastorePath);
}
} else {
virReportError(VIR_ERR_INTERNAL_ERROR,
goto cleanup;
} else {
/* Fall back to the path as key */
- if (VIR_STRDUP(key, datastorePath) < 0)
- goto cleanup;
+ key = g_strdup(datastorePath);
}
} else {
virReportError(VIR_ERR_INTERNAL_ERROR,
if (STRCASEEQ(queryParam->name, "transport")) {
VIR_FREE((*parsedUri)->transport);
- if (VIR_STRDUP((*parsedUri)->transport, queryParam->value) < 0)
- goto cleanup;
+ (*parsedUri)->transport = g_strdup(queryParam->value);
if (STRNEQ((*parsedUri)->transport, "http") &&
STRNEQ((*parsedUri)->transport, "https")) {
} else if (STRCASEEQ(queryParam->name, "vcenter")) {
VIR_FREE((*parsedUri)->vCenter);
- if (VIR_STRDUP((*parsedUri)->vCenter, queryParam->value) < 0)
- goto cleanup;
+ (*parsedUri)->vCenter = g_strdup(queryParam->value);
} else if (STRCASEEQ(queryParam->name, "no_verify")) {
if (virStrToLong_i(queryParam->value, NULL, 10, &noVerify) < 0 ||
(noVerify != 0 && noVerify != 1)) {
tmp = queryParam->value;
}
- if (VIR_STRDUP((*parsedUri)->proxy_hostname, tmp) < 0)
- goto cleanup;
+ (*parsedUri)->proxy_hostname = g_strdup(tmp);
if ((tmp = strchr((*parsedUri)->proxy_hostname, ':'))) {
if (tmp == (*parsedUri)->proxy_hostname) {
}
}
- if (VIR_STRDUP((*parsedUri)->path, uri->path) < 0)
- goto cleanup;
+ (*parsedUri)->path = g_strdup(uri->path);
if (!(*parsedUri)->transport)
(*parsedUri)->transport = g_strdup("https");
return -1;
}
- if (VIR_STRDUP(copyOfDatastorePath, datastorePath) < 0)
- goto cleanup;
+ copyOfDatastorePath = g_strdup(datastorePath);
/* Expected format: '[<datastore>] <path>' where <path> is optional */
if (!(tmp = STRSKIP(copyOfDatastorePath, "[")) || *tmp == ']' ||
goto cleanup;
}
- if (datastoreName &&
- VIR_STRDUP(*datastoreName, preliminaryDatastoreName) < 0) {
- goto cleanup;
- }
+ if (datastoreName)
+ *datastoreName = g_strdup(preliminaryDatastoreName);
preliminaryDirectoryAndFileName = strtok_r(NULL, "", &saveptr);
strspn(preliminaryDirectoryAndFileName, " ");
}
- if (directoryAndFileName &&
- VIR_STRDUP(*directoryAndFileName, preliminaryDirectoryAndFileName) < 0) {
- goto cleanup;
- }
+ if (directoryAndFileName)
+ *directoryAndFileName = g_strdup(preliminaryDirectoryAndFileName);
if (directoryName) {
/* Split <path> into <directory>/<file> and remove /<file> */
if (tmp)
*tmp = '\0';
- if (VIR_STRDUP(*directoryName, preliminaryDirectoryAndFileName) < 0)
- goto cleanup;
+ *directoryName = g_strdup(preliminaryDirectoryAndFileName);
}
result = 0;
char *escaped1;
char *escaped2 = NULL;
- if (VIR_STRDUP(replaced, string) < 0)
- return NULL;
+ replaced = g_strdup(string);
esxUtil_ReplaceSpecialWindowsPathChars(replaced);
}
if (esxVI_CURL_Alloc(&ctx->curl) < 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) {
+ esxVI_CURL_Connect(ctx->curl, parsedUri) < 0) {
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)
goto cleanup;
return -1;
}
- if (VIR_STRDUP(ctx->datacenterPath, ctx->datacenter->name) < 0)
- return -1;
+ ctx->datacenterPath = g_strdup(ctx->datacenter->name);
/* Lookup (Cluster)ComputeResource */
if (esxVI_LookupComputeResource(ctx, NULL, ctx->datacenter->hostFolder,
return -1;
}
- if (VIR_STRDUP(ctx->computeResourcePath, ctx->computeResource->name) < 0)
- return -1;
+ ctx->computeResourcePath = g_strdup(ctx->computeResource->name);
/* Lookup HostSystem */
if (esxVI_LookupHostSystem(ctx, NULL, ctx->computeResource->_reference,
return -1;
}
- if (VIR_STRDUP(ctx->hostSystemName, ctx->hostSystem->name) < 0)
- return -1;
+ ctx->hostSystemName = g_strdup(ctx->hostSystem->name);
return 0;
}
esxVI_ManagedObjectReference *root = NULL;
esxVI_Folder *folder = NULL;
- if (VIR_STRDUP(tmp, path) < 0)
- goto cleanup;
+ tmp = g_strdup(path);
/* Lookup Datacenter */
item = strtok_r(tmp, "/", &saveptr);
goto cleanup;
}
- if (VIR_STRDUP(ctx->hostSystemName, previousItem) < 0)
- goto cleanup;
+ ctx->hostSystemName = g_strdup(previousItem);
if (esxVI_LookupHostSystem(ctx, ctx->hostSystemName,
ctx->computeResource->_reference, NULL,
return -1;
}
- if (esxVI_TraversalSpec_Alloc(&traversalSpec) < 0 ||
- VIR_STRDUP(traversalSpec->name, name) < 0 ||
- VIR_STRDUP(traversalSpec->type, type) < 0 ||
- VIR_STRDUP(traversalSpec->path, path) < 0) {
+ if (esxVI_TraversalSpec_Alloc(&traversalSpec) < 0)
goto failure;
- }
+ traversalSpec->name = g_strdup(name);
+ traversalSpec->type = g_strdup(type);
+ traversalSpec->path = g_strdup(path);
traversalSpec->skip = esxVI_Boolean_False;
if (selectSetNames) {
currentSelectSetName = selectSetNames;
while (currentSelectSetName && *currentSelectSetName != '\0') {
- if (esxVI_SelectionSpec_Alloc(&selectionSpec) < 0 ||
- VIR_STRDUP(selectionSpec->name, currentSelectSetName) < 0 ||
- esxVI_SelectionSpec_AppendToList(&traversalSpec->selectSet,
- selectionSpec) < 0) {
+ if (esxVI_SelectionSpec_Alloc(&selectionSpec) < 0)
+ goto failure;
+
+ selectionSpec->name = g_strdup(currentSelectSetName);
+
+ if (esxVI_SelectionSpec_AppendToList(&traversalSpec->selectSet,
+ selectionSpec) < 0)
goto failure;
- }
selectionSpec = NULL;
currentSelectSetName += strlen(currentSelectSetName) + 1;
goto failure;
}
- if (VIR_STRDUP(*name, dynamicProperty->val->string) < 0)
- goto failure;
+ *name = g_strdup(dynamicProperty->val->string);
if (virVMXUnescapeHexPercent(*name) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
snapshotTree && count < nameslen;
snapshotTree = snapshotTree->_next) {
if (!(leaves && snapshotTree->childSnapshotList)) {
- if (VIR_STRDUP(names[count], snapshotTree->name) < 0)
- goto failure;
+ names[count] = g_strdup(snapshotTree->name);
count++;
}
datastoreName) < 0)
goto cleanup;
- if (VIR_STRDUP(fileName, directoryAndFileName) < 0)
- goto cleanup;
+ fileName = g_strdup(directoryAndFileName);
} else {
if (virAsprintf(&datastorePathWithoutFileName, "[%s] %s",
datastoreName, directoryName) < 0)
goto cleanup;
}
- if (VIR_STRDUP(fileName, directoryAndFileName + length + 1) < 0)
- goto cleanup;
+ fileName = g_strdup(directoryAndFileName + length + 1);
}
/* Lookup HostDatastoreBrowser */
if (!(*key)) {
/* Other files don't have a UUID, fall back to the path as key */
- if (VIR_STRDUP(*key, datastorePath) < 0)
- goto cleanup;
+ *key = g_strdup(datastorePath);
}
result = 0;
ESX_VI_CHECK_ARG_LIST(errorMessage);
- if (VIR_STRDUP(version, "") < 0)
- return -1;
+ version = g_strdup("");
if (esxVI_ObjectSpec_Alloc(&objectSpec) < 0)
goto cleanup;
goto cleanup;
VIR_FREE(version);
- if (VIR_STRDUP(version, updateSet->version) < 0)
- goto cleanup;
+ version = g_strdup(updateSet->version);
if (!updateSet->filterSet)
continue;
goto cleanup;
if (!taskInfo->error) {
- if (VIR_STRDUP(*errorMessage, _("Unknown error")) < 0)
- goto cleanup;
+ *errorMessage = g_strdup(_("Unknown error"));
} else if (!taskInfo->error->localizedMessage) {
- if (VIR_STRDUP(*errorMessage, taskInfo->error->fault->_actualType) < 0)
- goto cleanup;
+ *errorMessage = g_strdup(taskInfo->error->fault->_actualType);
} else {
if (virAsprintf(errorMessage, "%s - %s",
taskInfo->error->fault->_actualType,
for (hostScsiTopologyLun = hostScsiTopologyTarget->lun;
hostScsiTopologyLun;
hostScsiTopologyLun = hostScsiTopologyLun->_next) {
- if (STREQ(hostScsiTopologyLun->scsiLun, key) &&
- VIR_STRDUP(*poolName, candidate->iScsiName) < 0)
- goto cleanup;
+ if (STREQ(hostScsiTopologyLun->scsiLun, key))
+ *poolName = g_strdup(candidate->iScsiName);
}
/* hostScsiTopologyLun iteration done, terminate loop */
(*dest)->type = src->type;
- if (VIR_STRDUP((*dest)->other, src->other) < 0 ||
- VIR_STRDUP((*dest)->value, src->value) < 0) {
- goto failure;
- }
+ (*dest)->other = g_strdup(src->other);
+ (*dest)->value = g_strdup(src->value);
switch ((int)src->type) {
case esxVI_Type_Boolean:
if (esxVI_String_Alloc(&string) < 0)
return -1;
- if (VIR_STRDUP(string->value, value) < 0)
- goto failure;
+ string->value = g_strdup(value);
if (esxVI_String_AppendToList(stringList, string) < 0)
goto failure;
ESX_VI_CHECK_ARG_LIST(value);
*value = (char *)xmlNodeListGetString(node->doc, node->children, 1);
+ if (!*value)
+ *value = g_strdup("");
- return *value ? 0 : VIR_STRDUP(*value, "");
+ return 0;
}