[libvirt] [PATCH v2 3/5] conf: use glib allocation when parsing video props

Jonathon Jongsma posted 5 patches 5 years, 1 month ago
There is a newer version of this series
[libvirt] [PATCH v2 3/5] conf: use glib allocation when parsing video props
Posted by Jonathon Jongsma 5 years, 1 month ago
In preparation for some other improvements, switch to using glib
allocation and g_autofree when parsing the 'acceleration' and
'resolution' properties of the video device.

Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com>
---
 src/conf/domain_conf.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index ad1d3ffea6..269a6ec2c3 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -15289,7 +15289,7 @@ static virDomainVideoAccelDefPtr
 virDomainVideoAccelDefParseXML(xmlNodePtr node)
 {
     xmlNodePtr cur;
-    virDomainVideoAccelDefPtr def;
+    g_autofree virDomainVideoAccelDefPtr def = NULL;
     int val;
     g_autofree char *accel2d = NULL;
     g_autofree char *accel3d = NULL;
@@ -15311,8 +15311,7 @@ virDomainVideoAccelDefParseXML(xmlNodePtr node)
     if (!accel3d && !accel2d && !rendernode)
         return NULL;
 
-    if (VIR_ALLOC(def) < 0)
-        goto cleanup;
+    def = g_new0(virDomainVideoAccelDef, 1);
 
     if (accel3d) {
         if ((val = virTristateBoolTypeFromString(accel3d)) <= 0) {
@@ -15336,14 +15335,14 @@ virDomainVideoAccelDefParseXML(xmlNodePtr node)
         def->rendernode = virFileSanitizePath(rendernode);
 
  cleanup:
-    return def;
+    return g_steal_pointer(&def);
 }
 
 static virDomainVideoResolutionDefPtr
 virDomainVideoResolutionDefParseXML(xmlNodePtr node)
 {
     xmlNodePtr cur;
-    virDomainVideoResolutionDefPtr def;
+    g_autofree virDomainVideoResolutionDefPtr def = NULL;
     g_autofree char *x = NULL;
     g_autofree char *y = NULL;
 
@@ -15362,8 +15361,7 @@ virDomainVideoResolutionDefParseXML(xmlNodePtr node)
     if (!x || !y)
         return NULL;
 
-    if (VIR_ALLOC(def) < 0)
-        goto cleanup;
+    def = g_new0(virDomainVideoResolutionDef, 1);
 
     if (virStrToLong_uip(x, NULL, 10, &def->x) < 0) {
         virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
@@ -15378,7 +15376,7 @@ virDomainVideoResolutionDefParseXML(xmlNodePtr node)
     }
 
  cleanup:
-    return def;
+    return g_steal_pointer(&def);
 }
 
 static virDomainVideoDriverDefPtr
-- 
2.21.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list