]> xenbits.xensource.com Git - libvirt.git/commitdiff
Adapt to VIR_STRDUP and VIR_STRNDUP in src/hyperv/*
authorMichal Privoznik <mprivozn@redhat.com>
Fri, 3 May 2013 12:42:20 +0000 (14:42 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Thu, 9 May 2013 12:00:45 +0000 (14:00 +0200)
src/hyperv/hyperv_driver.c
src/hyperv/hyperv_util.c

index 7031fdbb611f2e92c00e8856f5a1d92420782864..dd8d0184758c37736bcfaab3bb5f12b77384eced 100644 (file)
@@ -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,11 @@ 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 (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 +907,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 +954,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;
 
index a55b9397a0a3e9f0575c87a19ad8dfd7e20ea75c..b7c2a17ad624580db666060fc148154eb667e250 100644 (file)
@@ -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;