--- src/hyperv/hyperv_driver.c | 35 +++++++++++------------------------ src/hyperv/hyperv_util.c | 15 +++++---------- 2 files changed, 16 insertions(+), 34 deletions(-) diff --git a/src/hyperv/hyperv_driver.c b/src/hyperv/hyperv_driver.c index 7031fdb..23d30e1 100644 --- a/src/hyperv/hyperv_driver.c +++ b/src/hyperv/hyperv_driver.c @@ -140,9 +140,7 @@ hypervConnectOpen(virConnectPtr conn, virConnectAuthPtr auth, unsigned int flags /* Request credentials */ if (conn->uri->user != NULL) { - username = strdup(conn->uri->user); - - if (username == NULL) { + if (VIR_STRDUP(username, conn->uri->user) < 0) { virReportOOMError(); goto cleanup; } @@ -257,9 +255,7 @@ hypervConnectGetHostname(virConnectPtr conn) goto cleanup; } - hostname = strdup(computerSystem->data->DNSHostName); - - if (hostname == NULL) { + if (VIR_STRDUP(hostname, computerSystem->data->DNSHostName) < 0) { virReportOOMError(); goto cleanup; } @@ -652,9 +648,9 @@ hypervDomainDestroy(virDomainPtr domain) static char * hypervDomainGetOSType(virDomainPtr domain ATTRIBUTE_UNUSED) { - char *osType = strdup("hvm"); + char *osType; - if (osType == NULL) { + if (VIR_STRDUP(osType, "hvm") < 0) { virReportOOMError(); return NULL; } @@ -908,20 +904,15 @@ hypervDomainGetXMLDesc(virDomainPtr domain, unsigned int flags) return NULL; } - def->name = strdup(computerSystem->data->ElementName); - - if (def->name == NULL) { + if (VIR_STRDUP(def->name, computerSystem->data->ElementName) < 0) { virReportOOMError(); 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) { + virReportOOMError(); + goto cleanup; } def->mem.max_balloon = memorySettingData->data->Limit * 1024; /* megabyte to kilobyte */ @@ -930,9 +921,7 @@ 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) { + if (VIR_STRDUP(def->os.type, "hvm") < 0) { virReportOOMError(); goto cleanup; } @@ -981,9 +970,7 @@ 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) { + if (VIR_STRDUP(names[count], computerSystem->data->ElementName) < 0) { virReportOOMError(); goto cleanup; } diff --git a/src/hyperv/hyperv_util.c b/src/hyperv/hyperv_util.c index a55b939..6d5f79a 100644 --- a/src/hyperv/hyperv_util.c +++ b/src/hyperv/hyperv_util.c @@ -27,6 +27,7 @@ #include "viralloc.h" #include "virlog.h" #include "viruuid.h" +#include "virstring.h" #include "hyperv_private.h" #include "hyperv_util.h" @@ -56,9 +57,7 @@ hypervParseUri(hypervParsedUri **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; } @@ -77,13 +76,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) { + virReportOOMError(); + goto cleanup; } result = 0; -- 1.8.1.5 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list