--- src/esx/esx_driver.c | 33 +++++++++---------------- src/esx/esx_interface_driver.c | 5 ++-- src/esx/esx_network_driver.c | 20 ++++++--------- src/esx/esx_storage_backend_iscsi.c | 14 ++++------- src/esx/esx_storage_backend_vmfs.c | 8 ++---- src/esx/esx_util.c | 37 +++++++++------------------- src/esx/esx_vi.c | 49 +++++++++---------------------------- src/esx/esx_vi_types.c | 22 +++++------------ 8 files changed, 58 insertions(+), 130 deletions(-) diff --git a/src/esx/esx_driver.c b/src/esx/esx_driver.c index dcf64b8..a5caafe 100644 --- a/src/esx/esx_driver.c +++ b/src/esx/esx_driver.c @@ -669,9 +669,7 @@ esxConnectToHost(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; } @@ -751,13 +749,10 @@ 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) { + virReportOOMError(); + goto cleanup; } result = 0; @@ -801,9 +796,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,9 +1271,7 @@ esxConnectGetHostname(virConnectPtr conn) } if (domainName == NULL || strlen(domainName) < 1) { - complete = strdup(hostName); - - if (complete == NULL) { + if (VIR_STRDUP(complete, hostName) < 0) { virReportOOMError(); goto cleanup; } @@ -1294,7 +1285,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,9 +2007,9 @@ esxDomainDestroy(virDomainPtr dom) static char * esxDomainGetOSType(virDomainPtr domain ATTRIBUTE_UNUSED) { - char *osType = strdup("hvm"); + char *osType; - if (osType == NULL) { + if (VIR_STRDUP(osType, "hvm") < 0) { virReportOOMError(); return NULL; } @@ -3577,9 +3568,9 @@ esxDomainSetAutostart(virDomainPtr domain, int autostart) static char * esxDomainGetSchedulerType(virDomainPtr domain ATTRIBUTE_UNUSED, int *nparams) { - char *type = strdup("allocation"); + char *type; - if (type == NULL) { + if (VIR_STRDUP(type, "allocation") < 0) { virReportOOMError(); return NULL; } diff --git a/src/esx/esx_interface_driver.c b/src/esx/esx_interface_driver.c index fe5194c..ba006a2 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,9 +115,7 @@ 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) { + if (VIR_STRDUP(names[count], physicalNic->device) < 0) { virReportOOMError(); goto cleanup; } diff --git a/src/esx/esx_network_driver.c b/src/esx/esx_network_driver.c index fd57b61..cb6a806 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,9 +123,7 @@ 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) { + if (VIR_STRDUP(names[count], hostVirtualSwitch->name) < 0) { virReportOOMError(); goto cleanup; } @@ -713,9 +712,7 @@ esxNetworkGetXMLDesc(virNetworkPtr network_, unsigned int flags) md5_buffer(hostVirtualSwitch->key, strlen(hostVirtualSwitch->key), def->uuid); - def->name = strdup(hostVirtualSwitch->name); - - if (def->name == NULL) { + if (VIR_STRDUP(def->name, hostVirtualSwitch->name) < 0) { virReportOOMError(); goto cleanup; } @@ -752,10 +749,8 @@ 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) { + if (VIR_STRDUP(def->forward.ifs[def->forward.nifs].device.dev, + physicalNic->device) < 0) { virReportOOMError(); goto cleanup; } @@ -823,9 +818,8 @@ 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) { + if (VIR_STRDUP(def->portGroups[def->nPortGroups].name, + networkName->value) < 0) { virReportOOMError(); goto cleanup; } diff --git a/src/esx/esx_storage_backend_iscsi.c b/src/esx/esx_storage_backend_iscsi.c index 941e800..57aa24b 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,9 +131,7 @@ 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) { + if (VIR_STRDUP(names[count], target->iScsiName) < 0) { virReportOOMError(); goto cleanup; } @@ -419,9 +418,7 @@ 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) { + if (VIR_STRDUP(names[count], scsiLun->deviceName) < 0) { virReportOOMError(); goto cleanup; } @@ -739,9 +736,8 @@ esxStorageBackendISCSIVolumeWipe(virStorageVolPtr volume ATTRIBUTE_UNUSED, static char * esxStorageBackendISCSIVolumeGetPath(virStorageVolPtr volume) { - char *path = strdup(volume->name); - - if (path == NULL) { + char *path; + if (VIR_STRDUP(path, volume->name) < 0) { virReportOOMError(); return NULL; } diff --git a/src/esx/esx_storage_backend_vmfs.c b/src/esx/esx_storage_backend_vmfs.c index dea6716..42efeb1 100644 --- a/src/esx/esx_storage_backend_vmfs.c +++ b/src/esx/esx_storage_backend_vmfs.c @@ -168,9 +168,7 @@ esxStorageBackendVMFSListPools(virConnectPtr conn, char **const names, goto cleanup; } - names[count] = strdup(dynamicProperty->val->string); - - if (names[count] == NULL) { + if (VIR_STRDUP(names[count], dynamicProperty->val->string) < 0) { virReportOOMError(); goto cleanup; } @@ -614,9 +612,7 @@ 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) { + if (VIR_STRDUP(names[count], fileInfo->path) < 0) { virReportOOMError(); goto cleanup; } diff --git a/src/esx/esx_util.c b/src/esx/esx_util.c index 4566fec..55efb17 100644 --- a/src/esx/esx_util.c +++ b/src/esx/esx_util.c @@ -65,9 +65,7 @@ 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) { + if (VIR_STRDUP((*parsedUri)->transport, queryParam->value) < 0) { virReportOOMError(); goto cleanup; } @@ -83,9 +81,7 @@ 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) { + if (VIR_STRDUP((*parsedUri)->vCenter, queryParam->value) < 0) { virReportOOMError(); goto cleanup; } @@ -137,9 +133,7 @@ esxUtil_ParseUri(esxUtil_ParsedUri **parsedUri, virURIPtr uri) tmp = queryParam->value; } - (*parsedUri)->proxy_hostname = strdup(tmp); - - if ((*parsedUri)->proxy_hostname == NULL) { + if (VIR_STRDUP((*parsedUri)->proxy_hostname, tmp) < 0) { virReportOOMError(); goto cleanup; } @@ -171,22 +165,15 @@ esxUtil_ParseUri(esxUtil_ParsedUri **parsedUri, virURIPtr uri) } } - if (uri->path != NULL) { - (*parsedUri)->path = strdup(uri->path); - - if ((*parsedUri)->path == NULL) { - virReportOOMError(); - goto cleanup; - } + if (uri->path && VIR_STRDUP((*parsedUri)->path, uri->path) < 0) { + virReportOOMError(); + goto cleanup; } - if ((*parsedUri)->transport == NULL) { - (*parsedUri)->transport = strdup("https"); - - if ((*parsedUri)->transport == NULL) { - virReportOOMError(); - goto cleanup; - } + if (!(*parsedUri)->transport && + VIR_STRDUP((*parsedUri)->transport, "https") < 0) { + virReportOOMError(); + goto cleanup; } result = 0; @@ -494,11 +481,11 @@ esxUtil_ReplaceSpecialWindowsPathChars(char *string) char * esxUtil_EscapeDatastoreItem(const char *string) { - char *replaced = strdup(string); + char *replaced; char *escaped1; char *escaped2 = NULL; - if (replaced == NULL) { + if (VIR_STRDUP(replaced, string) < 0) { virReportOOMError(); return NULL; } diff --git a/src/esx/esx_vi.c b/src/esx/esx_vi.c index ee48159..7245fbb 100644 --- a/src/esx/esx_vi.c +++ b/src/esx/esx_vi.c @@ -947,9 +947,7 @@ esxVI_Context_LookupManagedObjects(esxVI_Context *ctx) return -1; } - ctx->datacenterPath = strdup(ctx->datacenter->name); - - if (ctx->datacenterPath == NULL) { + if (VIR_STRDUP(ctx->datacenterPath, ctx->datacenter->name) < 0) { virReportOOMError(); return -1; } @@ -967,9 +965,7 @@ esxVI_Context_LookupManagedObjects(esxVI_Context *ctx) return -1; } - ctx->computeResourcePath = strdup(ctx->computeResource->name); - - if (ctx->computeResourcePath == NULL) { + if (VIR_STRDUP(ctx->computeResourcePath, ctx->computeResource->name) < 0) { virReportOOMError(); return -1; } @@ -981,9 +977,7 @@ esxVI_Context_LookupManagedObjects(esxVI_Context *ctx) return -1; } - ctx->hostSystemName = strdup(ctx->hostSystem->name); - - if (ctx->hostSystemName == NULL) { + if (VIR_STRDUP(ctx->hostSystemName, ctx->hostSystem->name) < 0) { virReportOOMError(); return -1; } @@ -1003,9 +997,7 @@ esxVI_Context_LookupManagedObjectsByPath(esxVI_Context *ctx, const char *path) esxVI_ManagedObjectReference *root = NULL; esxVI_Folder *folder = NULL; - tmp = strdup(path); - - if (tmp == NULL) { + if (VIR_STRDUP(tmp, path) < 0) { virReportOOMError(); goto cleanup; } @@ -1160,9 +1152,7 @@ esxVI_Context_LookupManagedObjectsByPath(esxVI_Context *ctx, const char *path) goto cleanup; } - ctx->hostSystemName = strdup(previousItem); - - if (ctx->hostSystemName == NULL) { + if (VIR_STRDUP(ctx->hostSystemName, previousItem) < 0) { virReportOOMError(); goto cleanup; } @@ -2498,9 +2488,7 @@ esxVI_GetVirtualMachineIdentity(esxVI_ObjectContent *virtualMachine, goto failure; } - *name = strdup(dynamicProperty->val->string); - - if (*name == NULL) { + if (VIR_STRDUP(*name, dynamicProperty->val->string) < 0) { virReportOOMError(); goto failure; } @@ -2611,9 +2599,7 @@ 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) { + if (VIR_STRDUP(names[count], snapshotTree->name) < 0) { virReportOOMError(); goto failure; } @@ -4388,9 +4374,7 @@ esxVI_WaitForTaskCompletion(esxVI_Context *ctx, return -1; } - version = strdup(""); - - if (version == NULL) { + if (VIR_STRDUP(version, "") < 0) { virReportOOMError(); return -1; } @@ -4469,9 +4453,7 @@ esxVI_WaitForTaskCompletion(esxVI_Context *ctx, } VIR_FREE(version); - version = strdup(updateSet->version); - - if (version == NULL) { + if (VIR_STRDUP(version, updateSet->version) < 0) { virReportOOMError(); goto cleanup; } @@ -4523,19 +4505,14 @@ esxVI_WaitForTaskCompletion(esxVI_Context *ctx, } if (taskInfo->error == NULL) { - *errorMessage = strdup(_("Unknown error")); - - if (*errorMessage == NULL) { + if (VIR_STRDUP(*errorMessage, _("Unknown error")) < 0) { virReportOOMError(); goto cleanup; } } else if (taskInfo->error->localizedMessage == NULL) { - *errorMessage = strdup(taskInfo->error->fault->_actualType); - - if (*errorMessage == NULL) { + if (VIR_STRDUP(*errorMessage, taskInfo->error->fault->_actualType) < 0) virReportOOMError(); goto cleanup; - } } else { if (virAsprintf(errorMessage, "%s - %s", taskInfo->error->fault->_actualType, @@ -4984,9 +4961,7 @@ esxVI_LookupStoragePoolNameByScsiLunKey(esxVI_Context *ctx, hostScsiTopologyLun != NULL; hostScsiTopologyLun = hostScsiTopologyLun->_next) { if (STREQ(hostScsiTopologyLun->scsiLun, key)) { - *poolName = strdup(candidate->iScsiName); - - if (*poolName == NULL) { + if (VIR_STRDUP(*poolName, candidate->iScsiName) < 0) { virReportOOMError(); goto cleanup; } diff --git a/src/esx/esx_vi_types.c b/src/esx/esx_vi_types.c index 7f40308..df2866d 100644 --- a/src/esx/esx_vi_types.c +++ b/src/esx/esx_vi_types.c @@ -1050,13 +1050,9 @@ 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) { + virReportOOMError(); + goto failure; } #define _DESERIALIZE_NUMBER(_type, _xsdType, _name, _min, _max) \ @@ -1177,9 +1173,7 @@ esxVI_String_AppendValueToList(esxVI_String **stringList, const char *value) return -1; } - string->value = strdup(value); - - if (string->value == NULL) { + if (VIR_STRDUP(string->value, value) < 0) { virReportOOMError(); goto failure; } @@ -1244,9 +1238,7 @@ esxVI_String_DeepCopyValue(char **dest, const char *src) return 0; } - *dest = strdup(src); - - if (*dest == NULL) { + if (VIR_STRDUP(*dest, src) < 0) { virReportOOMError(); return -1; } @@ -1328,9 +1320,7 @@ esxVI_String_DeserializeValue(xmlNodePtr node, char **value) *value = (char *)xmlNodeListGetString(node->doc, node->children, 1); if (*value == NULL) { - *value = strdup(""); - - if (*value == NULL) { + if (VIR_STRDUP(*value, "") < 0) { virReportOOMError(); return -1; } -- 1.8.1.5 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list