[libvirt PATCH 3/7] hyperv: use g_new0 instead of VIR_ALLOC*

Ján Tomko jtomko at redhat.com
Fri Sep 25 13:16:09 UTC 2020


Signed-off-by: Ján Tomko <jtomko at redhat.com>
---
 src/hyperv/hyperv_driver.c | 13 +++++--------
 src/hyperv/hyperv_util.c   |  3 +--
 src/hyperv/hyperv_wmi.c    | 13 +++----------
 3 files changed, 9 insertions(+), 20 deletions(-)

diff --git a/src/hyperv/hyperv_driver.c b/src/hyperv/hyperv_driver.c
index 9b181ebfff..b57325f2a5 100644
--- a/src/hyperv/hyperv_driver.c
+++ b/src/hyperv/hyperv_driver.c
@@ -128,8 +128,7 @@ hypervConnectOpen(virConnectPtr conn, virConnectAuthPtr auth,
     virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR);
 
     /* Allocate per-connection private data */
-    if (VIR_ALLOC(priv) < 0)
-        goto cleanup;
+    priv = g_new0(hypervPrivate, 1);
 
     if (hypervParseUri(&priv->parsedUri, conn->uri) < 0)
         goto cleanup;
@@ -1221,8 +1220,8 @@ hypervConnectListAllDomains(virConnectPtr conn,
          !MATCH(VIR_CONNECT_LIST_DOMAINS_NO_AUTOSTART)) ||
         (MATCH(VIR_CONNECT_LIST_DOMAINS_HAS_SNAPSHOT) &&
          !MATCH(VIR_CONNECT_LIST_DOMAINS_NO_SNAPSHOT))) {
-        if (domains && VIR_ALLOC_N(*domains, 1) < 0)
-            goto cleanup;
+        if (domains)
+            *domains = g_new0(virDomainPtr, 1);
 
         ret = 0;
         goto cleanup;
@@ -1251,8 +1250,7 @@ hypervConnectListAllDomains(virConnectPtr conn,
         goto cleanup;
 
     if (domains) {
-        if (VIR_ALLOC_N(doms, 1) < 0)
-            goto cleanup;
+        doms = g_new0(virDomainPtr, 1);
         ndoms = 1;
     }
 
@@ -1357,8 +1355,7 @@ hypervDomainSendKey(virDomainPtr domain, unsigned int codeset,
     if (hypervGetMsvmKeyboardList(priv, &query, &keyboard) < 0)
         goto cleanup;
 
-    if (VIR_ALLOC_N(translatedKeycodes, nkeycodes) < 0)
-        goto cleanup;
+    translatedKeycodes = g_new0(int, nkeycodes);
 
     /* translate keycodes to win32 and generate keyup scancodes. */
     for (i = 0; i < nkeycodes; i++) {
diff --git a/src/hyperv/hyperv_util.c b/src/hyperv/hyperv_util.c
index 2425d6a0c6..56c9e8bebd 100644
--- a/src/hyperv/hyperv_util.c
+++ b/src/hyperv/hyperv_util.c
@@ -45,8 +45,7 @@ hypervParseUri(hypervParsedUri **parsedUri, virURIPtr uri)
         return -1;
     }
 
-    if (VIR_ALLOC(*parsedUri) < 0)
-        return -1;
+    *parsedUri = g_new0(hypervParsedUri, 1);
 
     for (i = 0; i < uri->paramsCount; i++) {
         virURIParamPtr queryParam = &uri->params[i];
diff --git a/src/hyperv/hyperv_wmi.c b/src/hyperv/hyperv_wmi.c
index 917298d027..809f68a844 100644
--- a/src/hyperv/hyperv_wmi.c
+++ b/src/hyperv/hyperv_wmi.c
@@ -176,14 +176,9 @@ hypervCreateInvokeParamsList(hypervPrivate *priv, const char *method,
     if (hypervGetWmiClassInfo(priv, obj, &info) < 0)
         return NULL;
 
-    if (VIR_ALLOC(params) < 0)
-        return NULL;
+    params = g_new0(hypervInvokeParamsList, 1);
 
-    if (VIR_ALLOC_N(params->params,
-                HYPERV_DEFAULT_PARAM_COUNT) < 0) {
-        VIR_FREE(params);
-        return NULL;
-    }
+    params->params = g_new0(hypervParam, HYPERV_DEFAULT_PARAM_COUNT);
 
     params->method = method;
     params->ns = info->rootUri;
@@ -1052,9 +1047,7 @@ hypervEnumAndPull(hypervPrivate *priv, hypervWqlQueryPtr wqlQuery,
             goto cleanup;
         }
 
-        if (VIR_ALLOC(object) < 0)
-            goto cleanup;
-
+        object = g_new0(hypervObject, 1);
         object->info = wmiInfo;
         object->data.common = data;
 
-- 
2.26.2




More information about the libvir-list mailing list