render / rpms / libvirt

Forked from rpms/libvirt 10 months ago
Clone
a41c76
From 18b41d5bb489080b8be3c78d7f8436c9fb13087a Mon Sep 17 00:00:00 2001
a41c76
Message-Id: <18b41d5bb489080b8be3c78d7f8436c9fb13087a@dist-git>
a41c76
From: Jiri Denemark <jdenemar@redhat.com>
a41c76
Date: Tue, 26 May 2020 10:59:03 +0200
a41c76
Subject: [PATCH] cpu_x86: Use glib allocation for virCPUx86Model
a41c76
MIME-Version: 1.0
a41c76
Content-Type: text/plain; charset=UTF-8
a41c76
Content-Transfer-Encoding: 8bit
a41c76
a41c76
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
a41c76
Reviewed-by: Ján Tomko <jtomko@redhat.com>
a41c76
(cherry picked from commit ccc0c2e4de58d62308e224076a7aa979ae97b520)
a41c76
a41c76
https://bugzilla.redhat.com/show_bug.cgi?id=1840010
a41c76
a41c76
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
a41c76
Message-Id: <db624beaa5c879842c45b90269fb58a8f2fcfff2.1590483392.git.jdenemar@redhat.com>
a41c76
Reviewed-by: Ján Tomko <jtomko@redhat.com>
a41c76
---
a41c76
 src/cpu/cpu_x86.c | 31 ++++++++-----------------------
a41c76
 1 file changed, 8 insertions(+), 23 deletions(-)
a41c76
a41c76
diff --git a/src/cpu/cpu_x86.c b/src/cpu/cpu_x86.c
a41c76
index 3a598e35d2..373c34a834 100644
a41c76
--- a/src/cpu/cpu_x86.c
a41c76
+++ b/src/cpu/cpu_x86.c
a41c76
@@ -1111,29 +1111,18 @@ x86FeatureParse(xmlXPathContextPtr ctxt,
a41c76
 }
a41c76
 
a41c76
 
a41c76
-static virCPUx86ModelPtr
a41c76
-x86ModelNew(void)
a41c76
-{
a41c76
-    virCPUx86ModelPtr model;
a41c76
-
a41c76
-    if (VIR_ALLOC(model) < 0)
a41c76
-        return NULL;
a41c76
-
a41c76
-    return model;
a41c76
-}
a41c76
-
a41c76
-
a41c76
 static void
a41c76
 x86ModelFree(virCPUx86ModelPtr model)
a41c76
 {
a41c76
     if (!model)
a41c76
         return;
a41c76
 
a41c76
-    VIR_FREE(model->name);
a41c76
-    VIR_FREE(model->signatures);
a41c76
+    g_free(model->name);
a41c76
+    g_free(model->signatures);
a41c76
     virCPUx86DataClear(&model->data);
a41c76
-    VIR_FREE(model);
a41c76
+    g_free(model);
a41c76
 }
a41c76
+G_DEFINE_AUTOPTR_CLEANUP_FUNC(virCPUx86Model, x86ModelFree);
a41c76
 
a41c76
 
a41c76
 static int
a41c76
@@ -1161,9 +1150,7 @@ x86ModelCopy(virCPUx86ModelPtr model)
a41c76
 {
a41c76
     virCPUx86ModelPtr copy;
a41c76
 
a41c76
-    if (VIR_ALLOC(copy) < 0)
a41c76
-        return NULL;
a41c76
-
a41c76
+    copy = g_new0(virCPUx86Model, 1);
a41c76
     copy->name = g_strdup(model->name);
a41c76
 
a41c76
     if (x86ModelCopySignatures(copy, model) < 0) {
a41c76
@@ -1216,7 +1203,7 @@ x86ModelFromCPU(const virCPUDef *cpu,
a41c76
     if (cpu->type == VIR_CPU_TYPE_HOST &&
a41c76
         policy != VIR_CPU_FEATURE_REQUIRE &&
a41c76
         policy != -1)
a41c76
-        return x86ModelNew();
a41c76
+        return g_new0(virCPUx86Model, 1);
a41c76
 
a41c76
     if (cpu->model &&
a41c76
         (policy == VIR_CPU_FEATURE_REQUIRE || policy == -1)) {
a41c76
@@ -1228,7 +1215,7 @@ x86ModelFromCPU(const virCPUDef *cpu,
a41c76
 
a41c76
         model = x86ModelCopy(model);
a41c76
     } else {
a41c76
-        model = x86ModelNew();
a41c76
+        model = g_new0(virCPUx86Model, 1);
a41c76
     }
a41c76
 
a41c76
     if (!model)
a41c76
@@ -1540,9 +1527,7 @@ x86ModelParse(xmlXPathContextPtr ctxt,
a41c76
         goto cleanup;
a41c76
     }
a41c76
 
a41c76
-    if (!(model = x86ModelNew()))
a41c76
-        goto cleanup;
a41c76
-
a41c76
+    model = g_new0(virCPUx86Model, 1);
a41c76
     model->name = g_strdup(name);
a41c76
 
a41c76
     if (x86ModelParseDecode(model, ctxt) < 0)
a41c76
-- 
a41c76
2.26.2
a41c76