}
if (conn->uri->user != NULL) {
- username = strdup(conn->uri->user);
-
- if (username == NULL) {
- virReportOOMError();
+ if (VIR_STRDUP(username, conn->uri->user) < 0)
goto cleanup;
- }
} else {
username = virAuthGetUsername(conn, auth, "esx", "root", conn->uri->server);
VIR_WARN("The server is in maintenance mode");
}
- if (*vCenterIpAddress != NULL) {
- *vCenterIpAddress = strdup(*vCenterIpAddress);
-
- if (*vCenterIpAddress == NULL) {
- virReportOOMError();
- goto cleanup;
- }
- }
+ if (VIR_STRDUP(*vCenterIpAddress, *vCenterIpAddress) < 0)
+ goto cleanup;
result = 0;
}
if (conn->uri->user != NULL) {
- username = strdup(conn->uri->user);
-
- if (username == NULL) {
- virReportOOMError();
+ if (VIR_STRDUP(username, conn->uri->user) < 0) {
goto cleanup;
}
} else {
}
if (domainName == NULL || strlen(domainName) < 1) {
- complete = strdup(hostName);
-
- if (complete == NULL) {
- virReportOOMError();
+ if (VIR_STRDUP(complete, hostName) < 0)
goto cleanup;
- }
} else {
if (virAsprintf(&complete, "%s.%s", hostName, domainName) < 0) {
virReportOOMError();
cleanup:
/*
* If we goto cleanup in case of an error then complete is still NULL,
- * either strdup returned NULL or virAsprintf failed. When virAsprintf
+ * either VIR_STRDUP returned -1 or virAsprintf failed. When virAsprintf
* fails it guarantees setting complete to NULL
*/
esxVI_String_Free(&propertyNameList);
static char *
esxDomainGetOSType(virDomainPtr domain ATTRIBUTE_UNUSED)
{
- char *osType = strdup("hvm");
-
- if (osType == NULL) {
- virReportOOMError();
- return NULL;
- }
+ char *osType;
+ ignore_value(VIR_STRDUP(osType, "hvm"));
return osType;
}
static char *
esxDomainGetSchedulerType(virDomainPtr domain ATTRIBUTE_UNUSED, int *nparams)
{
- char *type = strdup("allocation");
+ char *type;
- if (type == NULL) {
- virReportOOMError();
+ if (VIR_STRDUP(type, "allocation") < 0)
return NULL;
- }
if (nparams != NULL) {
*nparams = 3; /* reservation, limit, shares */
#include "esx_vi.h"
#include "esx_vi_methods.h"
#include "esx_util.h"
+#include "virstring.h"
#define VIR_FROM_THIS VIR_FROM_ESX
for (physicalNic = physicalNicList; physicalNic != NULL;
physicalNic = physicalNic->_next) {
- names[count] = strdup(physicalNic->device);
-
- if (names[count] == NULL) {
- virReportOOMError();
+ if (VIR_STRDUP(names[count], physicalNic->device) < 0)
goto cleanup;
- }
++count;
}
#include "esx_vi.h"
#include "esx_vi_methods.h"
#include "esx_util.h"
+#include "virstring.h"
#define VIR_FROM_THIS VIR_FROM_ESX
for (hostVirtualSwitch = hostVirtualSwitchList; hostVirtualSwitch != NULL;
hostVirtualSwitch = hostVirtualSwitch->_next) {
- names[count] = strdup(hostVirtualSwitch->name);
-
- if (names[count] == NULL) {
- virReportOOMError();
+ if (VIR_STRDUP(names[count], hostVirtualSwitch->name) < 0)
goto cleanup;
- }
++count;
}
md5_buffer(hostVirtualSwitch->key, strlen(hostVirtualSwitch->key), def->uuid);
- def->name = strdup(hostVirtualSwitch->name);
-
- if (def->name == NULL) {
- virReportOOMError();
+ if (VIR_STRDUP(def->name, hostVirtualSwitch->name) < 0)
goto cleanup;
- }
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;
- def->forward.ifs[def->forward.nifs].device.dev
- = strdup(physicalNic->device);
-
- if (def->forward.ifs[def->forward.nifs].device.dev == NULL) {
- virReportOOMError();
+ if (VIR_STRDUP(def->forward.ifs[def->forward.nifs].device.dev,
+ physicalNic->device) < 0)
goto cleanup;
- }
++def->forward.nifs;
for (networkName = networkNameList; networkName != NULL;
networkName = networkName->_next) {
if (STREQ(networkName->value, hostPortGroup->spec->name)) {
- def->portGroups[def->nPortGroups].name = strdup(networkName->value);
-
- if (def->portGroups[def->nPortGroups].name == NULL) {
- virReportOOMError();
+ if (VIR_STRDUP(def->portGroups[def->nPortGroups].name,
+ networkName->value) < 0)
goto cleanup;
- }
if (hostPortGroup->spec->policy != NULL) {
if (esxShapingPolicyToBandwidth
#include "esx_vi.h"
#include "esx_vi_methods.h"
#include "esx_util.h"
+#include "virstring.h"
#define VIR_FROM_THIS VIR_FROM_ESX
*/
for (target = hostInternetScsiHba->configuredStaticTarget;
target != NULL && count < maxnames; target = target->_next) {
- names[count] = strdup(target->iScsiName);
-
- if (names[count] == NULL) {
- virReportOOMError();
+ if (VIR_STRDUP(names[count], target->iScsiName) < 0)
goto cleanup;
- }
++count;
}
hostScsiTopologyLun != NULL && count < maxnames;
hostScsiTopologyLun = hostScsiTopologyLun->_next) {
if (STREQ(hostScsiTopologyLun->scsiLun, scsiLun->key)) {
- names[count] = strdup(scsiLun->deviceName);
-
- if (names[count] == NULL) {
- virReportOOMError();
+ if (VIR_STRDUP(names[count], scsiLun->deviceName) < 0)
goto cleanup;
- }
++count;
}
static char *
esxStorageBackendISCSIVolumeGetPath(virStorageVolPtr volume)
{
- char *path = strdup(volume->name);
-
- if (path == NULL) {
- virReportOOMError();
- return NULL;
- }
+ char *path;
+ ignore_value(VIR_STRDUP(path, volume->name));
return path;
}
goto cleanup;
}
- names[count] = strdup(dynamicProperty->val->string);
-
- if (names[count] == NULL) {
- virReportOOMError();
+ if (VIR_STRDUP(names[count], dynamicProperty->val->string) < 0)
goto cleanup;
- }
++count;
break;
for (fileInfo = searchResults->file; fileInfo != NULL;
fileInfo = fileInfo->_next) {
if (length < 1) {
- names[count] = strdup(fileInfo->path);
-
- if (names[count] == NULL) {
- virReportOOMError();
+ if (VIR_STRDUP(names[count], fileInfo->path) < 0)
goto cleanup;
- }
} else if (virAsprintf(&names[count], "%s/%s", directoryAndFileName,
fileInfo->path) < 0) {
virReportOOMError();
VIR_FREE(datastorePath);
if (length < 1) {
- if (!(volumeName = strdup(fileInfo->path))) {
- virReportOOMError();
+ if (VIR_STRDUP(volumeName, fileInfo->path) < 0)
goto cleanup;
- }
} else if (virAsprintf(&volumeName, "%s/%s",
directoryAndFileName,
fileInfo->path) < 0) {
if (STRCASEEQ(queryParam->name, "transport")) {
VIR_FREE((*parsedUri)->transport);
- (*parsedUri)->transport = strdup(queryParam->value);
-
- if ((*parsedUri)->transport == NULL) {
- virReportOOMError();
+ if (VIR_STRDUP((*parsedUri)->transport, queryParam->value) < 0)
goto cleanup;
- }
if (STRNEQ((*parsedUri)->transport, "http") &&
STRNEQ((*parsedUri)->transport, "https")) {
} else if (STRCASEEQ(queryParam->name, "vcenter")) {
VIR_FREE((*parsedUri)->vCenter);
- (*parsedUri)->vCenter = strdup(queryParam->value);
-
- if ((*parsedUri)->vCenter == NULL) {
- virReportOOMError();
+ if (VIR_STRDUP((*parsedUri)->vCenter, queryParam->value) < 0)
goto cleanup;
- }
} else if (STRCASEEQ(queryParam->name, "no_verify")) {
if (virStrToLong_i(queryParam->value, NULL, 10, &noVerify) < 0 ||
(noVerify != 0 && noVerify != 1)) {
tmp = queryParam->value;
}
- (*parsedUri)->proxy_hostname = strdup(tmp);
-
- if ((*parsedUri)->proxy_hostname == NULL) {
- virReportOOMError();
+ if (VIR_STRDUP((*parsedUri)->proxy_hostname, tmp) < 0)
goto cleanup;
- }
if ((tmp = strchr((*parsedUri)->proxy_hostname, ':')) != NULL) {
if (tmp == (*parsedUri)->proxy_hostname) {
}
}
- if (uri->path != NULL) {
- (*parsedUri)->path = strdup(uri->path);
-
- if ((*parsedUri)->path == NULL) {
- virReportOOMError();
- goto cleanup;
- }
- }
-
- if ((*parsedUri)->transport == NULL) {
- (*parsedUri)->transport = strdup("https");
+ if (VIR_STRDUP((*parsedUri)->path, uri->path) < 0)
+ goto cleanup;
- if ((*parsedUri)->transport == NULL) {
- virReportOOMError();
- goto cleanup;
- }
- }
+ if (!(*parsedUri)->transport &&
+ VIR_STRDUP((*parsedUri)->transport, "https") < 0)
+ goto cleanup;
result = 0;
char *
esxUtil_EscapeDatastoreItem(const char *string)
{
- char *replaced = strdup(string);
+ char *replaced;
char *escaped1;
char *escaped2 = NULL;
- if (replaced == NULL) {
- virReportOOMError();
+ if (VIR_STRDUP(replaced, string) < 0)
return NULL;
- }
esxUtil_ReplaceSpecialWindowsPathChars(replaced);
return -1;
}
- ctx->datacenterPath = strdup(ctx->datacenter->name);
-
- if (ctx->datacenterPath == NULL) {
- virReportOOMError();
+ if (VIR_STRDUP(ctx->datacenterPath, ctx->datacenter->name) < 0)
return -1;
- }
/* Lookup (Cluster)ComputeResource */
if (esxVI_LookupComputeResource(ctx, NULL, ctx->datacenter->hostFolder,
return -1;
}
- ctx->computeResourcePath = strdup(ctx->computeResource->name);
-
- if (ctx->computeResourcePath == NULL) {
- virReportOOMError();
+ if (VIR_STRDUP(ctx->computeResourcePath, ctx->computeResource->name) < 0)
return -1;
- }
/* Lookup HostSystem */
if (esxVI_LookupHostSystem(ctx, NULL, ctx->computeResource->_reference,
return -1;
}
- ctx->hostSystemName = strdup(ctx->hostSystem->name);
-
- if (ctx->hostSystemName == NULL) {
- virReportOOMError();
+ if (VIR_STRDUP(ctx->hostSystemName, ctx->hostSystem->name) < 0)
return -1;
- }
return 0;
}
esxVI_ManagedObjectReference *root = NULL;
esxVI_Folder *folder = NULL;
- tmp = strdup(path);
-
- if (tmp == NULL) {
- virReportOOMError();
+ if (VIR_STRDUP(tmp, path) < 0)
goto cleanup;
- }
/* Lookup Datacenter */
item = strtok_r(tmp, "/", &saveptr);
goto cleanup;
}
- ctx->hostSystemName = strdup(previousItem);
-
- if (ctx->hostSystemName == NULL) {
- virReportOOMError();
+ if (VIR_STRDUP(ctx->hostSystemName, previousItem) < 0)
goto cleanup;
- }
if (esxVI_LookupHostSystem(ctx, ctx->hostSystemName,
ctx->computeResource->_reference, NULL,
goto failure;
}
- *name = strdup(dynamicProperty->val->string);
-
- if (*name == NULL) {
- virReportOOMError();
+ if (VIR_STRDUP(*name, dynamicProperty->val->string) < 0)
goto failure;
- }
if (virVMXUnescapeHexPercent(*name) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
snapshotTree != NULL && count < nameslen;
snapshotTree = snapshotTree->_next) {
if (!(leaves && snapshotTree->childSnapshotList)) {
- names[count] = strdup(snapshotTree->name);
-
- if (names[count] == NULL) {
- virReportOOMError();
+ if (VIR_STRDUP(names[count], snapshotTree->name) < 0)
goto failure;
- }
count++;
}
return -1;
}
- version = strdup("");
-
- if (version == NULL) {
- virReportOOMError();
+ if (VIR_STRDUP(version, "") < 0)
return -1;
- }
if (esxVI_ObjectSpec_Alloc(&objectSpec) < 0) {
goto cleanup;
}
VIR_FREE(version);
- version = strdup(updateSet->version);
-
- if (version == NULL) {
- virReportOOMError();
+ if (VIR_STRDUP(version, updateSet->version) < 0)
goto cleanup;
- }
if (updateSet->filterSet == NULL) {
continue;
}
if (taskInfo->error == NULL) {
- *errorMessage = strdup(_("Unknown error"));
-
- if (*errorMessage == NULL) {
- virReportOOMError();
+ if (VIR_STRDUP(*errorMessage, _("Unknown error")) < 0)
goto cleanup;
- }
} else if (taskInfo->error->localizedMessage == NULL) {
- *errorMessage = strdup(taskInfo->error->fault->_actualType);
-
- if (*errorMessage == NULL) {
- virReportOOMError();
+ if (VIR_STRDUP(*errorMessage, taskInfo->error->fault->_actualType) < 0)
goto cleanup;
- }
} else {
if (virAsprintf(errorMessage, "%s - %s",
taskInfo->error->fault->_actualType,
hostScsiTopologyTarget != NULL;
hostScsiTopologyTarget = hostScsiTopologyTarget->_next) {
candidate = esxVI_HostInternetScsiTargetTransport_DynamicCast
- (hostScsiTopologyTarget->transport);
+ (hostScsiTopologyTarget->transport);
if (candidate != NULL) {
/* iterate hostScsiTopologyLun list to find matching key */
for (hostScsiTopologyLun = hostScsiTopologyTarget->lun;
hostScsiTopologyLun != NULL;
hostScsiTopologyLun = hostScsiTopologyLun->_next) {
- if (STREQ(hostScsiTopologyLun->scsiLun, key)) {
- *poolName = strdup(candidate->iScsiName);
-
- if (*poolName == NULL) {
- virReportOOMError();
- goto cleanup;
- }
- }
+ if (STREQ(hostScsiTopologyLun->scsiLun, key) &&
+ VIR_STRDUP(*poolName, candidate->iScsiName) < 0)
+ goto cleanup;
}
/* hostScsiTopologyLun iteration done, terminate loop */
(*anyType)->value =
(char *)xmlNodeListGetString(node->doc, node->children, 1);
- if ((*anyType)->value == NULL) {
- (*anyType)->value = strdup("");
-
- if ((*anyType)->value == NULL) {
- virReportOOMError();
- goto failure;
- }
- }
+ if (!(*anyType)->value && VIR_STRDUP((*anyType)->value, "") < 0)
+ goto failure;
#define _DESERIALIZE_NUMBER(_type, _xsdType, _name, _min, _max) \
do { \
return -1;
}
- string->value = strdup(value);
-
- if (string->value == NULL) {
- virReportOOMError();
+ if (VIR_STRDUP(string->value, value) < 0)
goto failure;
- }
if (esxVI_String_AppendToList(stringList, string) < 0) {
goto failure;
return 0;
}
- *dest = strdup(src);
-
- if (*dest == NULL) {
- virReportOOMError();
- return -1;
- }
-
- return 0;
+ return VIR_STRDUP(*dest, src);
}
/* esxVI_String_CastFromAnyType */
*value = (char *)xmlNodeListGetString(node->doc, node->children, 1);
- if (*value == NULL) {
- *value = strdup("");
-
- if (*value == NULL) {
- virReportOOMError();
- return -1;
- }
- }
-
- return 0;
+ return *value ? 0 : VIR_STRDUP(*value, "");
}