---
src/esx/esx_driver.c | 43 ++++++--------------
src/esx/esx_interface_driver.c | 7 +---
src/esx/esx_network_driver.c | 28 ++++---------
src/esx/esx_storage_backend_iscsi.c | 21 +++-------
src/esx/esx_storage_backend_vmfs.c | 16 ++------
src/esx/esx_util.c | 45 +++++----------------
src/esx/esx_vi.c | 79 +++++++------------------------------
src/esx/esx_vi_types.c | 36 +++--------------
8 files changed, 58 insertions(+), 217 deletions(-)
diff --git a/src/esx/esx_driver.c b/src/esx/esx_driver.c
index dcf64b8..714a218 100644
--- a/src/esx/esx_driver.c
+++ b/src/esx/esx_driver.c
@@ -669,12 +669,8 @@ esxConnectToHost(esxPrivate *priv,
}
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);
@@ -751,14 +747,9 @@ esxConnectToHost(esxPrivate *priv,
VIR_WARN("The server is in maintenance mode");
}
- if (*vCenterIpAddress != NULL) {
- *vCenterIpAddress = strdup(*vCenterIpAddress);
-
- if (*vCenterIpAddress == NULL) {
- virReportOOMError();
- goto cleanup;
- }
- }
+ if (!*vCenterIpAddress &&
+ VIR_STRDUP(*vCenterIpAddress, *vCenterIpAddress) < 0)
+ goto cleanup;
result = 0;
@@ -801,9 +792,7 @@ esxConnectToVCenter(esxPrivate *priv,
}
if (conn->uri->user != NULL) {
- username = strdup(conn->uri->user);
-
- if (username == NULL) {
+ if (VIR_STRDUP(username, conn->uri->user) < 0) {
virReportOOMError();
goto cleanup;
}
@@ -1278,12 +1267,8 @@ esxConnectGetHostname(virConnectPtr conn)
}
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();
@@ -1294,7 +1279,7 @@ esxConnectGetHostname(virConnectPtr conn)
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 NULL or virAsprintf failed. When virAsprintf
* fails it guarantees setting complete to NULL
*/
esxVI_String_Free(&propertyNameList);
@@ -2016,13 +2001,9 @@ esxDomainDestroy(virDomainPtr dom)
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;
}
@@ -3577,12 +3558,10 @@ esxDomainSetAutostart(virDomainPtr domain, int autostart)
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 */
diff --git a/src/esx/esx_interface_driver.c b/src/esx/esx_interface_driver.c
index fe5194c..7875ccf 100644
--- a/src/esx/esx_interface_driver.c
+++ b/src/esx/esx_interface_driver.c
@@ -35,6 +35,7 @@
#include "esx_vi.h"
#include "esx_vi_methods.h"
#include "esx_util.h"
+#include "virstring.h"
#define VIR_FROM_THIS VIR_FROM_ESX
@@ -114,12 +115,8 @@ esxConnectListInterfaces(virConnectPtr conn, char **const names, int
maxnames)
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;
}
diff --git a/src/esx/esx_network_driver.c b/src/esx/esx_network_driver.c
index fd57b61..a4842da 100644
--- a/src/esx/esx_network_driver.c
+++ b/src/esx/esx_network_driver.c
@@ -35,6 +35,7 @@
#include "esx_vi.h"
#include "esx_vi_methods.h"
#include "esx_util.h"
+#include "virstring.h"
#define VIR_FROM_THIS VIR_FROM_ESX
@@ -122,12 +123,8 @@ esxConnectListNetworks(virConnectPtr conn, char **const names, int
maxnames)
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;
}
@@ -713,12 +710,8 @@ esxNetworkGetXMLDesc(virNetworkPtr network_, unsigned int flags)
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;
@@ -752,13 +745,9 @@ esxNetworkGetXMLDesc(virNetworkPtr network_, unsigned int flags)
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;
@@ -823,12 +812,9 @@ esxNetworkGetXMLDesc(virNetworkPtr network_, unsigned int flags)
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
diff --git a/src/esx/esx_storage_backend_iscsi.c b/src/esx/esx_storage_backend_iscsi.c
index 941e800..a22adb4 100644
--- a/src/esx/esx_storage_backend_iscsi.c
+++ b/src/esx/esx_storage_backend_iscsi.c
@@ -38,6 +38,7 @@
#include "esx_vi.h"
#include "esx_vi_methods.h"
#include "esx_util.h"
+#include "virstring.h"
#define VIR_FROM_THIS VIR_FROM_ESX
@@ -130,12 +131,8 @@ esxStorageBackendISCSIListPools(virConnectPtr conn, char **const
names,
*/
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;
}
@@ -419,12 +416,8 @@ esxStorageBackendISCSIPoolListVolumes(virStoragePoolPtr pool, char
**const names
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;
}
@@ -739,13 +732,9 @@ esxStorageBackendISCSIVolumeWipe(virStorageVolPtr volume
ATTRIBUTE_UNUSED,
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;
}
diff --git a/src/esx/esx_storage_backend_vmfs.c b/src/esx/esx_storage_backend_vmfs.c
index 5d6f183..dd638ad 100644
--- a/src/esx/esx_storage_backend_vmfs.c
+++ b/src/esx/esx_storage_backend_vmfs.c
@@ -168,12 +168,8 @@ esxStorageBackendVMFSListPools(virConnectPtr conn, char **const
names,
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;
@@ -614,12 +610,8 @@ esxStorageBackendVMFSPoolListVolumes(virStoragePoolPtr pool, char
**const names,
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();
@@ -791,10 +783,8 @@ esxStorageBackendVMFSVolumeLookupByKey(virConnectPtr conn, const char
*key)
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) {
diff --git a/src/esx/esx_util.c b/src/esx/esx_util.c
index 4566fec..62268aa 100644
--- a/src/esx/esx_util.c
+++ b/src/esx/esx_util.c
@@ -65,12 +65,8 @@ esxUtil_ParseUri(esxUtil_ParsedUri **parsedUri, virURIPtr uri)
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")) {
@@ -83,12 +79,8 @@ esxUtil_ParseUri(esxUtil_ParsedUri **parsedUri, virURIPtr uri)
} 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)) {
@@ -137,12 +129,8 @@ esxUtil_ParseUri(esxUtil_ParsedUri **parsedUri, virURIPtr uri)
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) {
@@ -171,23 +159,12 @@ esxUtil_ParseUri(esxUtil_ParsedUri **parsedUri, virURIPtr uri)
}
}
- 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 (uri->path && 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;
@@ -494,14 +471,12 @@ esxUtil_ReplaceSpecialWindowsPathChars(char *string)
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);
diff --git a/src/esx/esx_vi.c b/src/esx/esx_vi.c
index ee48159..5fd0693 100644
--- a/src/esx/esx_vi.c
+++ b/src/esx/esx_vi.c
@@ -947,12 +947,8 @@ esxVI_Context_LookupManagedObjects(esxVI_Context *ctx)
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,
@@ -967,12 +963,8 @@ esxVI_Context_LookupManagedObjects(esxVI_Context *ctx)
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,
@@ -981,12 +973,8 @@ esxVI_Context_LookupManagedObjects(esxVI_Context *ctx)
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;
}
@@ -1003,12 +991,8 @@ esxVI_Context_LookupManagedObjectsByPath(esxVI_Context *ctx, const
char *path)
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);
@@ -1160,12 +1144,8 @@ esxVI_Context_LookupManagedObjectsByPath(esxVI_Context *ctx, const
char *path)
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,
@@ -2498,12 +2478,8 @@ esxVI_GetVirtualMachineIdentity(esxVI_ObjectContent
*virtualMachine,
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",
@@ -2611,12 +2587,8 @@ esxVI_GetSnapshotTreeNames(esxVI_VirtualMachineSnapshotTree
*snapshotTreeList,
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++;
}
@@ -4388,12 +4360,8 @@ esxVI_WaitForTaskCompletion(esxVI_Context *ctx,
return -1;
}
- version = strdup("");
-
- if (version == NULL) {
- virReportOOMError();
+ if (VIR_STRDUP(version, "") < 0)
return -1;
- }
if (esxVI_ObjectSpec_Alloc(&objectSpec) < 0) {
goto cleanup;
@@ -4469,12 +4437,8 @@ esxVI_WaitForTaskCompletion(esxVI_Context *ctx,
}
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;
@@ -4523,19 +4487,11 @@ esxVI_WaitForTaskCompletion(esxVI_Context *ctx,
}
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,
@@ -4976,21 +4932,16 @@ esxVI_LookupStoragePoolNameByScsiLunKey(esxVI_Context *ctx,
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 */
diff --git a/src/esx/esx_vi_types.c b/src/esx/esx_vi_types.c
index 7f40308..4596520 100644
--- a/src/esx/esx_vi_types.c
+++ b/src/esx/esx_vi_types.c
@@ -1050,14 +1050,8 @@ esxVI_AnyType_Deserialize(xmlNodePtr node, esxVI_AnyType
**anyType)
(*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 { \
@@ -1177,12 +1171,8 @@ esxVI_String_AppendValueToList(esxVI_String **stringList, const
char *value)
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;
@@ -1244,14 +1234,7 @@ esxVI_String_DeepCopyValue(char **dest, const char *src)
return 0;
}
- *dest = strdup(src);
-
- if (*dest == NULL) {
- virReportOOMError();
- return -1;
- }
-
- return 0;
+ return VIR_STRDUP(*dest, src);
}
/* esxVI_String_CastFromAnyType */
@@ -1327,16 +1310,7 @@ esxVI_String_DeserializeValue(xmlNodePtr node, char **value)
*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, "");
}
--
1.8.1.5