--- src/hyperv/hyperv_driver.c | 50 ++++++++++------------------------------------ src/hyperv/hyperv_util.c | 18 +++++------------ 2 files changed, 15 insertions(+), 53 deletions(-) diff --git a/src/hyperv/hyperv_driver.c b/src/hyperv/hyperv_driver.c index 7031fdb..2c18cb8 100644 --- a/src/hyperv/hyperv_driver.c +++ b/src/hyperv/hyperv_driver.c @@ -140,12 +140,8 @@ hypervConnectOpen(virConnectPtr conn, virConnectAuthPtr auth, unsigned int flags /* Request credentials */ 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, "hyperv", "administrator", conn->uri->server); @@ -257,12 +253,7 @@ hypervConnectGetHostname(virConnectPtr conn) goto cleanup; } - hostname = strdup(computerSystem->data->DNSHostName); - - if (hostname == NULL) { - virReportOOMError(); - goto cleanup; - } + ignore_value(VIR_STRDUP(hostname, computerSystem->data->DNSHostName)); cleanup: hypervFreeObject(priv, (hypervObject *)computerSystem); @@ -652,13 +643,9 @@ hypervDomainDestroy(virDomainPtr domain) static char * hypervDomainGetOSType(virDomainPtr domain ATTRIBUTE_UNUSED) { - char *osType = strdup("hvm"); - - if (osType == NULL) { - virReportOOMError(); - return NULL; - } + char *osType; + ignore_value(VIR_STRDUP(osType, "hvm")); return osType; } @@ -908,21 +895,12 @@ hypervDomainGetXMLDesc(virDomainPtr domain, unsigned int flags) return NULL; } - def->name = strdup(computerSystem->data->ElementName); - - if (def->name == NULL) { - virReportOOMError(); + if (VIR_STRDUP(def->name, computerSystem->data->ElementName) < 0) goto cleanup; - } - - if (virtualSystemSettingData->data->Notes != NULL) { - def->description = strdup(virtualSystemSettingData->data->Notes); - if (def->description == NULL) { - virReportOOMError(); - goto cleanup; - } - } + if (virtualSystemSettingData->data->Notes && + VIR_STRDUP(def->description, virtualSystemSettingData->data->Notes) < 0) + goto cleanup; def->mem.max_balloon = memorySettingData->data->Limit * 1024; /* megabyte to kilobyte */ def->mem.cur_balloon = memorySettingData->data->VirtualQuantity * 1024; /* megabyte to kilobyte */ @@ -930,12 +908,8 @@ hypervDomainGetXMLDesc(virDomainPtr domain, unsigned int flags) def->vcpus = processorSettingData->data->VirtualQuantity; def->maxvcpus = processorSettingData->data->VirtualQuantity; - def->os.type = strdup("hvm"); - - if (def->os.type == NULL) { - virReportOOMError(); + if (VIR_STRDUP(def->os.type, "hvm") < 0) goto cleanup; - } /* FIXME: devices section is totally missing */ @@ -981,12 +955,8 @@ hypervConnectListDefinedDomains(virConnectPtr conn, char **const names, int maxn for (computerSystem = computerSystemList; computerSystem != NULL; computerSystem = computerSystem->next) { - names[count] = strdup(computerSystem->data->ElementName); - - if (names[count] == NULL) { - virReportOOMError(); + if (VIR_STRDUP(names[count], computerSystem->data->ElementName) < 0) goto cleanup; - } ++count; diff --git a/src/hyperv/hyperv_util.c b/src/hyperv/hyperv_util.c index a55b939..b7c2a17 100644 --- a/src/hyperv/hyperv_util.c +++ b/src/hyperv/hyperv_util.c @@ -29,6 +29,7 @@ #include "viruuid.h" #include "hyperv_private.h" #include "hyperv_util.h" +#include "virstring.h" #define VIR_FROM_THIS VIR_FROM_HYPERV @@ -56,12 +57,8 @@ hypervParseUri(hypervParsedUri **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")) { @@ -77,14 +74,9 @@ hypervParseUri(hypervParsedUri **parsedUri, virURIPtr uri) } } - if ((*parsedUri)->transport == NULL) { - (*parsedUri)->transport = strdup("https"); - - if ((*parsedUri)->transport == NULL) { - virReportOOMError(); - goto cleanup; - } - } + if (!(*parsedUri)->transport && + VIR_STRDUP((*parsedUri)->transport, "https") < 0) + goto cleanup; result = 0; -- 1.8.1.5 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list